Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle message failure in MSMQ bindings for WCF

Tags:

.net

wcf

msmq

I have create a WCF service and am utilising netMsmqBinding binding.

This is a simple service that passes a Dto to my service method and does not expect a response. The message is placed in an MSMQ, and once picked up inserted into a database.

What is the best method to make sure no data is being lost.

I have tried the 2 following methods:

  1. Throw an exception

    This places the message in a dead letter queue for manual perusal. I can process this when my strvice starts

  2. set the receiveRetryCount="3" on the binding

    After 3 tries - which happen instantanously, this seems to leave the message in queue, but fault my service. Restarting my service repeats this process.

Ideally I would like to do the follow:

Try process the message

  • If this fails, wait 5 minutes for that message and try again.
  • If that process fails 3 times, move the message to a dead letter queue.
  • Restarting the service will push all messages from the dead letter queue back into the queue so that it can be processed.

Can I achieve this? If so how? Can you point me to any good articles on how best to utilize WCF and MSMQ for my given sceneria.

Any help would be much appreciated. Thanks!

Some additional information

I am using MSMQ 3.0 on Windows XP and Windows Server 2003. Unfortunately I can't use the built in poison message support targeted at MSMQ 4.0 and Vista/2008.

like image 634
WebDude Avatar asked Sep 17 '08 11:09

WebDude


People also ask

How does MSMQ work with WCF?

MSMQ is Microsoft Message Queuing developed by Microsoft and deployed in windows operating system. MSMQ Queue ensures that reliable messaging between a client and a Windows Communication Foundation (WCF) service. So first we need to enable this feature in our operating system.

What is the replacement for MSMQ?

Kafka, RabbitMQ, IBM MQ, Azure Service Bus, and ActiveMQ are the most popular alternatives and competitors to MSMQ.

How do you clean MSMQ?

Description. The Clear-MsmqQueue cmdlet clears queues. Specify queues to clear by using MessageQueue objects. This cmdlet returns a MessageQueue object that represents the cleared outgoing queue.


1 Answers

I think with MSMQ (avaiable only on Vista) you might be able to to do like this:

<bindings>
    <netMsmqBinding>
        <binding name="PosionMessageHandling"
             receiveRetryCount="3"
             retryCycleDelay="00:05:00"
             maxRetryCycles="3"
             receiveErrorHandling="Move" />
    </netMsmqBinding>
</bindings>

WCF will immediately retry for ReceiveRetryCount times after the first call failure. After the batch has failed the message is moved to the retry queue. After a delay of RetryCycleDelay minute, the message moved from the retry queue to the endpoint queue and the batch is retried. This will be repeated MaxRetryCycle time. If all that fails the message is handled according to receiveErrorHandling which can be move (to poison queue), reject, drop or fault

By the way a good text about WCF and MSMQ is the chapther 9 of Progammig WCF book from Juval Lowy

like image 165
aogan Avatar answered Oct 06 '22 22:10

aogan