我可以更改工作流服务的 MSMQ 消息错误处理行为吗?

发布于 2024-11-07 06:36:55 字数 362 浏览 4 评论 0原文

我有一个工作流服务,它有一些监听 MSMQ 队列的接收。我想实现以下行为:

  1. 如果发生关联异常(即工作流实例消失),则丢弃该消息。
  2. 如果发生 InstanceLockException(即,此工作流实例正在另一台服务器上执行某些操作),则将该消息放入重试队列中。

我尝试将 TransactedReceiveScope 放在 Receive 活动周围,但它会将消息放入重试队列中,以解决相关错误。另外,它在重负载下会导致很多问题。

如果没有 TransactedReceiveScope,如果出现 InstanceLockException,消息就会被丢弃。

有没有办法实现这种行为(也许通过行为扩展)?

I have a Workflow Service that has a few receives that listen to MSMQ queues. I would like to implement the following behavior:

  1. If a correlation exception occurs (ie - workflow instance is gone), throw away the message.
  2. If an InstanceLockException occurs (ie - this workflow instance is doing something on another server), put the message in the retry queue.

I have tried putting TransactedReceiveScope around the Receive activities, but it will put the message in the retry queue on a correlation error. Plus, it causes a lot of problems under heavy load.

Without the TransactedReceiveScope, the message is thrown away if there is an InstanceLockException.

Is there a way to implement this behavior (maybe via behavior extensions)?

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

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

发布评论

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

评论(3

请远离我 2024-11-14 06:36:55

您可以实现 WCF 的 IErrorHandler 来捕获所有未处理的异常是由您的应用程序还是 WCF 引发的。使用 netMsmqBinding 时必须小心的是,在此处理程序中抛出错误意味着消息已“成功”处理并且将从队列中取出。在您的情况下,当发生 InstanceLockException 时,如果您希望发生内置的 MSMQ 4 重试处理,则必须让它保持未处理状态。您还需要允许 PoisonMessageException 保持未处理状态,以便进行正确的 MSMQ 重试。

You can implement a IErrorHandler for WCF to catch all unhandled exceptions whether thrown by your app or by WCF. The thing you have to be careful about with the netMsmqBinding is that throwing a fault in this handler means the message has been "successfully" processed and it will taken off the queue. In your case when InstanceLockException occurs, you'll have to let it remain unhandled if you want the built-in MSMQ 4 retry handling to occur. You'll also need to allow the PoisonMessageException to remain unhandled for proper MSMQ retrying to occur.

哽咽笑 2024-11-14 06:36:55

我不熟悉使用工作流,但知道 MSMQ 和 WCF 是如何工作的,你可以尝试这个

当 CorrelationException 发生时:

  • 捕获异常
  • 从服务方法返回

由于你的服务方法不会抛出异常,它会认为消息已成功发送已处理并将其从队列中删除。

当 InstanceLockException 发生时:

  • 捕获异常
  • 并重新抛出异常

由于您的服务方法抛出异常,它会认为消息未成功处理并将其移至重试队列。

I'm not familiar with using Workflow, but knowing how MSMQ and WCF work you could try this

When a CorrelationException occurs:

  • Catch the exception
  • Return from your service method

Since your service method doesn't throw an exception it will think the message was successfully processed and remove it from the queue.

When a InstanceLockException occurs:

  • Catch the exception
  • rethrow the exception

Since your service method throws and exception it will think the message was not successfully processed and move it to the retry queue.

腹黑女流氓 2024-11-14 06:36:55

我认为您必须创建 WCF 自定义行为来捕获这些异常。

I think you'll have to create a WCF custom behavior to catch those exceptions.

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