简体   繁体   English

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

[英]Can I Change the Behavior of MSMQ Message Error Handling by a Workflow Service?

I have a Workflow Service that has a few receives that listen to MSMQ queues. 我有一个工作流服务,其中有一些接收程序可以监听MSMQ队列。 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. 如果发生InstanceLockException(即,此工作流实例在另一台服务器上正在做某事),请将消息放入重试队列。

I have tried putting TransactedReceiveScope around the Receive activities, but it will put the message in the retry queue on a correlation error. 我已经尝试将TransactedReceiveScope放在Receive活动周围,但是它将在相关错误时将消息放入重试队列中。 Plus, it causes a lot of problems under heavy load. 另外,它在重负载下会引起很多问题。

Without the TransactedReceiveScope, the message is thrown away if there is an InstanceLockException. 没有TransactedReceiveScope,如果存在InstanceLockException,则会丢弃该消息。

Is there a way to implement this behavior (maybe via behavior extensions)? 有没有办法实现这种行为(可能通过行为扩展)?

You can implement a IErrorHandler for WCF to catch all unhandled exceptions whether thrown by your app or by WCF. 您可以为WCF实现IErrorHandler,以捕获所有未处理的异常,无论这些异常是由您的应用程序还是由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. 使用netMsmqBinding时要注意的一点是,在此处理程序中引发错误意味着消息已“成功”处理,并且将从队列中删除。 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. 对于发生InstanceLockException的情况,如果希望进行内置MSMQ 4重试处理,则必须让它保持未处理状态。 You'll also need to allow the PoisonMessageException to remain unhandled for proper MSMQ retrying to occur. 您还需要允许PoisonMessageException保持未处理状态,以便正确进行MSMQ重试。

I'm not familiar with using Workflow, but knowing how MSMQ and WCF work you could try this 我对使用Workflow不熟悉,但是了解MSMQ和WCF的工作原理后,您可以尝试一下

When a CorrelationException occurs: 当发生CorrelationException时:

  • 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: 发生InstanceLockException时:

  • 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. 由于您的服务方法抛出异常,它将认为消息未成功处理,并将其移至重试队列。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM