Send failed messages to $DeadLetterQueue (AzureServiceBus)

I’m doing a project for a client using NServiceBus and Azure Service Bus.

For one particular service, they would like failed messages to end up in the ASB dead letter queue.
I expected the code below to do just that:


NServiceBus logs something like this:

Moving message ‘71ba2662-3f8f-4f67-9a5f-cf3898e0f201’ to the error queue ‘myqueue/$DeadLetterQueue’ because processing failed due to an exception…

Good, I thought, done. However, instead of the message residing in the DLQ, it ends up in the Transfer DLQ. A custom property is added:

DeadLetterReason: The transfer destination entity does not exist.

I don’t understand how this could be, because every queue implicitly has a DLQ. Has anyone done this before, and if so, how? What am I missing?

Hi Marcel,

Dead-letter queue (DLQ) is a special / system queue in Service Bus. It was not intended to be used for a scenario where user code sends messages. Its purpose is to store messages that have failed processing or certain conditions have taken place. These scenarios would cause messages to dead-letter:

  1. Eixceeded number of processing attempts (MaxDeliveryCount)
  2. An explicit indication that the message is poisonous and cannot be processed (explicit dead-lettering by user code).
  3. Messages expire (TimeToLive) and the queue was instructed to dead-letter expired messages.
  4. Subscription filter evaluation resulted in no subscribers (only intended for testing purposes)

Only in those scenarios, messages will be moved by the broker to the DLQ.

NServiceBus only moves messages to the DLQ when the incoming message cannot be processed for the reason of being a poisonous message (failing to deserialize it or malformed message that cannot be ingested). For anything else, the Error queue is the destination if the processing is not successful.

Could you elaborate on why in this specific case rather than sending messages to the error queue they’d be sent to a DLQ?

1 Like