WCF 服务中数据的保证处理

发布于 2024-10-07 01:13:02 字数 421 浏览 8 评论 0原文

我有一个 WCF 服务,可以处理来自 SAP 的数万条记录的源。该服务调用采用 XElement 作为其主要参数,并处理 XML 以更新数据库中的记录。当前的目的是异步调用 WCF 服务,并使服务调用将包含已处理的每条记录的状态的同一文档发送回调用者。

我也在研究多线程数据处理的方法,尽管这最终可能不会给我带来任何好处。

因为这可能需要一段时间,所以我担心如果 WCF 服务终止、重新启动等会发生什么。我需要知道我已经处理了哪些记录,还没有处理哪些记录,并且能够完成处理关于剩余的记录。

我能想到的最好办法是更新每个节点的状态(无论如何,我必须这样做,以发送回调用者),并将该文件保存到硬盘驱动器。但保存这么大的文件(可能保存 100,000 次)似乎不太可行。

在处理这些记录时,我还可以使用哪些其他策略来跟踪这些记录?

蒂亚!
詹姆斯

I have a WCF service that processes a feed of tens of thousands of records from SAP. The service call takes an XElement as its main parameter and processes the XML to update records in our database. The current intent is to have the WCF service be called asynchronously, and to have the service call send back to the caller the same document with statuses for each record processed.

I'm also looking into ways to multithread the processing of the data, though this may not end up buying me anything.

Because this could take a while, I'm concerned about what will happen if the WCF services dies, gets restarted, etc. I need to know which records I've processed, and which I haven't, and be able to complete processing on the remaining records.

The best I've been able to come up with is to update each node with a status (I have to do this, anyway, to send back to the caller), and save this file to the hard drive. But saving a file that large potentially 100,000 times doesn't really seem feasible.

What other strategies could I use to track these records as I process them?

TIA!
James

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

感受沵的脚步 2024-10-14 01:13:02

我认为使用 MSMQ 是满足您概述的大部分需求的好方法。如果您将节点分解为消息并将它们输入事务队列中。

  • 扩展数据处理
    通过拥有更多会更容易
    机器在队列一上处理
    你已经发挥了最大的能力
    一。
  • 如果 WCF“死机、重新启动等”,您不会丢失任何内容。
  • 在这种情况下,您将遇到的真正问题是让客户端弄清楚服务在处理过程中所处的位置。队列消息只是一种方式。您可能需要另一个服务调用来评估处理队列的状态。

MSMQ WCF 操作方法链接:

http://msdn.microsoft.com/en -us/library/ms789048.aspx

http://code.msdn.microsoft.com/msmqpluswcf

I see using a MSMQ as being a great way to fulfill most of the needs you outlined about. If you broke the nodes into messages and entered them in a transactional queue.

  • Scaling the processing of the data
    would be easier through having more
    machines processing on the queue one
    you maxed out the capabilities of
    one.
  • If WCF "dies, gets restarted, etc" you don't lose anything.
  • The real problem you will have with this scenario getting the client to figure out where the service is at in the processing. The queue messages are one way only. You would probably need another service call that would evaluate the status of processing the queue.

Links to MSMQ WCF how-to's:

http://msdn.microsoft.com/en-us/library/ms789048.aspx

http://code.msdn.microsoft.com/msmqpluswcf

杯别 2024-10-14 01:13:02

也许您可以首先将记录(来自 XML)放入数据库中,也许放在一个特殊的“要处理的记录”表中。每行还可以用某种方式标记,以将它们与特定请求相关联。处理数据库中的行。在处理每一个时,更新状态字段(对应于您在 XmlElement 上更新的节点状态)。完成后,您可以返回并更新 XML(如果您在此期间没有崩溃),也可以生成新的 XML(如果您无法往返转换 XML->database-,则可能会出现问题) > XML。

如果服务终止,检查数据库以查找尚未处理的记录并完成处理它们应该相对简单,

或者可以将 XML 文件写入磁盘一次,在数据库中保留一个表。仅保存“状态”字段(以及一个或多个键,以便您再次在 XML 文件中找到相应的记录),处理记录,更新数据库“状态”表。完成后,更新状态字段。通过从“状态”表中读取状态来一次性写入 XML 文件。

同样,如果服务终止,检查“状态”表以查看哪些行已被处理、哪些行尚未处理应该足够简单。

祝你好运!

Maybe you could put the records (from your XML) in your database first, maybe in a special "records to be processed" table. Each row might also be tagged with some way to correlate them with a specific request. Process the rows from the database. As you process each one, update the status field (corresponding to the node status that you would have updated on the XmlElement). When you are finished, you could either go back and update the XML (if you haven't crashed in the meantime) or you could generate new XML (could be problematic if you can't round trip the conversion XML->database->XML.

If the service dies, it should be relatively simple to examine the database to find the records that have not been processed and finish processing them.

Alternatively, could write the XML file to disk once, keep a table in the database that holds ONLY the "status" field (and one or more keys to allow you to find the corresponding record in the XML file again), process the records, update the database "status" table as you go. When finished, update the status fields in the XML file in one fell swoop by reading the status from the "status" table.

Again, if the service dies, it should be simple enough to examine the "status" table to see which rows have been processed and which have not.

Good luck!

·深蓝 2024-10-14 01:13:02

如果您的源数据库和目标数据库都是 SQL Server,那么您应该忘记中间人,直接使用数据库中的内置队列支持:服务代理。与 MSMQ 相比,您可以获得许多优势:

  • 高可用性。 Service Broker 内置于数据库中,因此您已经实施的数据库高可用性和灾难可恢复性解决方案也将自动采用您的消息传递解决方案。您的集群或数据库镜像解决方案将开箱即用,并且消息传递将通过数据库故障转移透明地进行故障转移。
  • 恢复一致性。将消息和数据放在同一个恢复单元(“数据库”)中可以实现简单的备份恢复。对于存储在 MSMQ 中的消息和存储在数据库中的数据,除非冻结处理,否则不可能获得一致的备份。
  • 路由。 SSB 允许队列移动到新的物理位置而不中断消息流。请参阅 Service Broker 路由
  • 增加容量。 MSMQ 的大小限制非常小(每个队列 4GB),在生产中可能会很快超出范围,从而造成灾难性的结果。 SSB 限制为每条消息 2GB,队列大小限制是数据库大小限制。
  • 由于本地事务而不是分布式事务,吞吐量显着提高。使用 MSMQ,您必须将数据库和 MSMQ 注册到分布式事务中,在入队末尾和出队末尾进行机器人操作。这极大地降低了 MSMQ 情况下的吞吐量。

还有其他优点:

  • 队列可查询性:可以使用 T-SQL SELECT 一种编程 API 来查询消息队列
  • :T-SQL。您不需要学习 MSMQ 接口(MSMQ 上的 WCF 通道只不过是 MSMQ API 上的浅垫片,与您之前可能使用过的其他通道不同)。通过 SSB,您可以使用现有的 T-SQL 专业知识在 T-SQL 中进行编程。
  • 激活。当您的消息到达时,存储过程将启动执行。
  • 会话语义:对话
  • 消息关联并发保护:对话组锁
  • 状态管理
  • 可扩展性:MySpace 使用 SQL Server Service Broker 保护 1 PB 数据的完整性

您丢失的一件事是 WCF 服务模型编程。 WCF 确实使编写演示应用程序变得非常容易,您将失去它。

If your source and destination databases are SQL Server, then you should forget about middle-men and go straight to the built-in queuing support in the database: Service Broker. You get a number of advantages over MSMQ:

  • High Availability. Service Broker is built into the database, so the database high availability and disaster recoverability solution you already have implemented will automatically pick up your messaging solution too. Your cluster or database mirroring solution will work out-of-the-box and the messaging will fail-over transparently with the database failover.
  • recovery consistency. Having you messages and you data in the same recovery unit (the 'database') allows for simple backup-restore. With messages stored in MSMQ and data stored in database is not possible to have a consistent backup unless you freeze processing.
  • routing. SSB allows for queues to move to new physical locations w/o interrupting the message stream. See Service Broker Routing.
  • increased capacity. MSMQ have a very small size limit (4GB per queue) which can be quickly overrun in production, with disastrous results. SSB limit is 2GB per message and the queue size limits are the database size limits.
  • significantly higher throughput due local transactions instead of distributed transaction. With MSMQ you must enroll the database and the MSMQ into a distributed transaction, bot at the end where you enqueue and at the end where you dequeue. This dramatically reduces the throughput in MSMQ case.

There are other advantages too:

The one thing you loose is the WCF service model programming. WCF makes it indeed extremely easy to write demo apps and you'll loose that.

琉璃繁缕 2024-10-14 01:13:02

您是否考虑过消息传递服务器,例如 Microsoft 消息队列

Have you considered a messaging server, such as Microsoft Message Queuing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文