开发者

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. I would like to implement the following behavior:

  1. If开发者_Go百科 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)?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜