

Var serviceBusConnection = new ServiceBusConnection (connectionString ) var deadletterPath = EntityNameHelper.
Service bus dead letter queue how to#
We’ve now seen how to cause a message to Dead Letter, and read the Dead Letter queue next we’re going to investigate re-submitting the message.Īs a quick side not - you can’t really re-submit a message - as you’ll see, what we actually do is to complete the dead letter message, and send a copy back to the queue. If you forcibly dead letter the message then you have the option to add this: if you choose not to then it will not be present (hence the checks around the properties), but mostly, these will be available. When a message is dead lettered, the properties DeadLetterReason and DeadLetterErrorDescription may get added to the message. Effectively, all you can do with a Dead Letter message is to complete it. The delivery count inside the dead letter queue does not increase, but it does retain the number that it had from the original queue.
Service bus dead letter queue code#
The code above sets up a MessageReceiver for the dead letter queue. ReceiveAsync ( ) string messageBody = Encoding. PeekLock ) var message = await deadLetterReceiver. FormatDeadLetterPath (QUEUE\_NAME ) var deadLetterReceiver = new MessageReceiver (connectionString, deadletterPath, ReceiveMode. There are a few reasons that a message can be considered “poison” and dead lettered some of the most common are: The solution is to have a dedicated queue that holds these messages: it’s called a Dead Letter Queue - it’s kind of like a holding bay for the car.

The Service Bus can’t deliver any messages until this message has gone, and this message can’t go, because there’s something wrong with it. (I have no knowledge of what a car assembly line looks like, outside of the film Christine, so apologies if this is incorrect).Ī message that can’t be processed is often called a poison message, and it causes exactly this problem. The person that fits the steering wheel is behind the bonnet fitter, and there’s no space for him to move the car that he’s just fitted the wheel to the dashboard fitter can’t pass onto the steering wheel, and so on. Meanwhile, the entire assembly line has stopped. They draft the workers in from all over the plant, but can’t get the bonnet fitted. After a while, he goes to get his superviser, and they both try. However, the guy that’s fitting the bonnet can’t get it to sit right in the hinges he tries and tries, but it won’t fit. The car in question has just come through to have a bonnet fitted (hood for any American readers). To describe what the dead letter queue does, I invite you to think about an assembly line for a car. What is the Dead Letter Queue, and what has it ever done for me?

In this post, I’m going to focus on the Dead Letter Queue in more detail. I’ve been writing about and speaking about Azure Service Bus a lot recently.
