使用 ConcurrencyMode.Multiple 模式保留 WCF 服务中的消息顺序

发布于 2024-11-15 14:07:27 字数 170 浏览 7 评论 0原文

有一个 WCF 服务处理传入请求,并为每个传入消息生成相应的输出消息,并将其发送到另一个 WCF 服务。消息到来的顺序很重要并且不能被打乱。因此,服务应该按照服务接收消息的顺序生成相应的输出消息。同时处理请求也很重要,这样才能从多核 CPU 中受益。

在这种情况下,保留输入和输出之间消息顺序的最佳方法是什么?

There is a WCF service which handles incoming requests and for each incoming message produces a corresponding output message which is sent to another WCF service. The order in which messages come is important and cannot be disturbed. So the service should produce the corresponding output messages in the same order in which they are received by the service. Also it's important to handle requests concurrently so that to benefit from multicore CPU.

What is the best approach to preserving order of messages between inputs and outputs in this case?

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

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

发布评论

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

评论(1

茶花眉 2024-11-22 14:07:27

这完全取决于您的实施。 WCF 只能强制有序传送(通过可靠会话或 MSMQ),以便您可以确保消息按照发送的顺序接收,但没有任何功能可以确保您的操作将按照相同的顺序发送消息(一个消息的处理速度可以比之前收到的另一条消息更快)。如果您想按顺序处理消息,请将 ConcurrencyMode 设置为 Multiple 只会使事情变得非常复杂。您必须手动同步操作,这将减少并发性,并且在最坏的情况下回退到接近 ConcurrencyMode.Single。同步可能很难实现,因为在操作中做到这一点是不够的 - WCF 通道堆栈处理输出消息也必须同步。

That is completely up to your implementation. WCF can only enforce ordered delivery (either through reliable session or MSMQ) so that you can be sure that messages are received in the order they were sent but there is no feature which will ensure that your operation will send messages in the same order (one message can be processed faster then another received earlier). If you want to process messages in order setting ConcurrencyMode to Multiple will only make things terribly complicated. You will have to manually synchronize operations which will reduce concurrency and in the worst case fallback close to ConcurrencyMode.Single. Synchronization can be hard to achieve because it is not enough to do it in the operation - WCF channel stack processing of output messages must also be synchronized.

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