Every Azure Service Bus queue and topic subscription has a built-in dead-letter sub-queue that holds messages which could not be delivered or processed. To handle it from Spring Boot, set a sensible maximum delivery count, dead-letter poison messages explicitly with a reason, and run a separate receiver on the dead-letter sub-queue that inspects, alerts on or resubmits those messages using the Azure Service Bus Java SDK.
The dead-letter queue (DLQ) is not a queue you create. It exists automatically, it is not itself dead-lettered, and messages in it never expire, so you must drain it yourself.
Messages move to the DLQ in these cases:
| Cause | Dead-letter reason set by Service Bus |
|---|---|
| Delivery attempts exceeded the queue's maximum delivery count (default 10) | MaxDeliveryCountExceeded |
| Message time-to-live expired and dead-lettering on expiration is enabled | TTLExpiredException |
| A subscription filter rule threw an error, if enabled for the subscription | FilterEvaluationException |
| Your code called dead-letter explicitly | Whatever reason you pass |
Message time-to-live expiry only dead-letters when "dead lettering on message expiration" is enabled on the queue or subscription. Delivery attempts are counted each time a message is locked and then abandoned or its lock expires, so a handler that throws consumes one attempt per try.
Use the Azure SDK, or the Spring Cloud Azure starter, which manages versions and authentication:
Set the maximum delivery count and the lock duration when you create the queue (Azure portal, Bicep, Terraform or the CLI), because these decide how often a message is retried. With the administration client you can also change them from code:
In production prefer infrastructure as code and give the application only the data roles it needs (Azure Service Bus Data Receiver and Data Sender) with managed identity rather than a connection string.
A ServiceBusProcessorClient receives messages in the background. Distinguish errors that can succeed on retry from errors that never will, and send the second kind to the DLQ immediately instead of burning delivery attempts:
Disabling auto-complete gives you explicit control over each outcome: complete, abandon or dead-letter. Every abandon() raises the delivery count, so after the limit Service Bus dead-letters the message for you.
Open a receiver on the dead-letter sub-queue with SubQueue.DEAD_LETTER_QUEUE. This is the supported equivalent of the older path form <queue>/$deadletterqueue:
The reason and description tell you whether the message failed because of a bug, bad data or expiry. Log them with the message ID and push a metric so you can alert when the DLQ depth grows (the active message count of the dead-letter sub-queue is available in Azure Monitor).
Service Bus cannot move a message back to the main queue. You receive it from the DLQ, send a copy to the main queue, then complete the original so it is removed:
Only resubmit after fixing the cause. Resubmitting the same poison message just sends it around the loop again. Consider adding an application property such as a resubmit counter, and keep a manual approval step for sensitive data.
No. Messages in the dead-letter sub-queue stay until you receive and complete them, so the DLQ can grow without bound if nobody drains it.
Yes. Any receiver in peek-lock mode can call deadLetter on a received message with DeadLetterOptions.
The default is 10. Lower it (for example to 3 to 5) when failures are rarely transient, so poison messages reach the DLQ faster.
No. The dead-letter sub-queue cannot be dead-lettered, which is why you need a process that reads and resolves its content.
Service Bus gives every queue and subscription a dead-letter sub-queue. Set the delivery count and expiry behaviour deliberately, dead-letter permanent failures with a reason, read the DLQ with SubQueue.DEAD_LETTER_QUEUE, and resubmit by sending a copy to the main queue and completing the original. Monitor its depth like any other production queue.