NServiceBus relies heavily on the underlying queuing system to make sure that messages gets delivered in a robust and timely fashion. In order to spot miss configurations it's very important to monitor the dead letter queues (DLQ's). You can think of the dead letter queue as a dumping ground for messages that can't be delivered by the queuing system. This post focus on MSMQ but the general ideas apply to the other queuing systems as well.

Can all messages end up in the DLQ?

If your using NServiceBus this would be all messages since we make sure to set the required flags that tells MSMQ to enable the DLQ (negative source journaling in msmq lingo). This means there is no way you can loose valuable business data even if the queuing system is miss configured. More info on the dead letter queues in MSMQ can be found here.

When do they end up there?

Messages gets moved to  the DLQ when the queuing system has tried to deliver a message for a while but decides to give up. This time is usually configurable and in MSMQ this happens when either time-to-reach-queue(TTRQ)  or time-to-be-received(TTBR) for the message has expired.

The TTRQ is usually 4 days by default but can be adjusted per machine. TTBR is also 4 days by default but can be controlled on a message per message basis by adding the [TimeToBeReceived] attribute to your NServiceBus message definitions.

So how do I monitor this?

While the error queue in NServiceBus is usually system wide the DLQ's are machine specific. This means that you have to monitor all your machines to detect messages ending up in any of the DLQ's. There are many ways to do this, write a powershell script that periodically looks at the DLQ(s) , MSMQ has 2 different ones,  and sound the alarm. To do this just use the System.Messaging.MessageQueue class in your script. The address is:


Another option is to use your favorite monitoring tool and watch the "Msmq Queue -> Computer Queues ->Messages in Queue " performance counter.

The image below shows this on my machine.

Note that the "Messages in queue" counter gives you the number of messages in both the DLQ's.


Make sure to monitor your DLQ's to detect message queuing issues!

Hope this helps!