Search code examples
msmqnservicebus

NServiceBus and "Dead Letter" queues?


So, I am new to MSMQ and NServiceBus. I played around with demos and got a working scenario going with NServiceBus. (Getting my own up and running was even easier than following the demo thanks to the new Modeling tools!)

I then went and presented my plan (based off my work with the demo and my own model) to my co-workers. Two of them were versed in using MSMQ and started asking me questions about how I will handle "Dead Letters".

I had never heard of "Dead Letters". They explained that it is queue used for messages that things cannot be sent (either because the other end refuses them or if the other end is not there).

The concern of my co-workers is that if we don't have Dead Letter queues then how will we stop a message from blocking the queue? (If the queue is FIFO and the top message can't be sent, then it blocks the other messages behind it right?)

On the other hand, if we have "Dead Letter" queues how are they managed? (Do I get an event from NServiceBus that tells me a new message is in the Dead Letter queue? How do I configure when a message will go to the Dead Letter queue? How can I try to re-send a Dead Letter message?)

So basically, how does NServiceBus deal with undeliverable messages?


Solution

  • Typically, you specify an error queue as well, which is where messages that couldn't be sent will go. Look at their MSMQ example: http://docs.particular.net/nservicebus/msmq/transportconfig & http://docs.particular.net/nservicebus/msmq/connection-strings

    <MsmqTransportConfig InputQueue="MyClient" ErrorQueue="error" 
                     NumberOfWorkerThreads="1" MaxRetries="5"/>
    

    In this scenario, the error queue will reside on the same machine as the input queue. This may also be a remote queue, if preferred. MaxRetries refers to the number of attempts to send before it gets put into the error queue. How you choose to handle the error queue is up to you, however.