我可以更改工作流服务的 MSMQ 消息错误处理行为吗?
我有一个工作流服务,它有一些监听 MSMQ 队列的接收。我想实现以下行为:
- 如果发生关联异常(即工作流实例消失),则丢弃该消息。
- 如果发生 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:
- If a correlation exception occurs (ie - workflow instance is gone), throw away the message.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以实现 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.
我不熟悉使用工作流,但知道 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:
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:
Since your service method throws and exception it will think the message was not successfully processed and move it to the retry queue.
我认为您必须创建 WCF 自定义行为来捕获这些异常。
I think you'll have to create a WCF custom behavior to catch those exceptions.