Azure Service Bus entities (queues/topics) support a Time to Live (TTL). When the TTL passes the message expires. On expiry, the system deletes the message OR moves it to the Dead-Letter Queue (DLQ). Does Service Bus have another setting to delete messages from the DLQ after a specified period? For instance, to avoid passing size quotas, we might like to delete messages from the DLQ after six months.
See also:
Do messages in dead letter queues in Azure Service Bus expire?
Azure Service Bus doesn't have an expiration option on the dead-letter queues. This is likely intentional, as the system shouldn't just lose those messages but rather do something about them.
Sometimes, monitoring all dead-letter queues for total size and whatnot is inconvenient. One option is to create a centralized DLQ. That will allow the following:
For example, let's say you've got two queues, test-dlq
and test-dlq2
. You'd configure those to auto-forward dead-lettered messages to a 3rd queue, test-dlq-all
. With that, when you have messages that are received by test-dlq
or test-dlq2
and dead-lettering,
Those messages will end up in the centralized "DLQ" queue (test-dlq-all
).
The nice part is whenever you have messages auto-forwarded, you'll always know where they originally dead-lettered.
For example, let's say you've got two messages, each from a different queue, ending up in test-dlq-all
, the centralized "DLQ".
Inspecting its messages will reveal a system property, DeadLetterSource
, stamped with the name of the queue it was dead-lettered initially in.
This solution lets you set TTL on the test-dlq-all
queue and have messages auto-perged.
Also, worth mentioning that it's possible to either set up dead-lettering with the centralized "DLQ" or get messaged dead-lettered as a result of failing processing that exceeds MaxDeliveryCount
. For that reason, it is worth wither monitoring test-dlq-all
s DLQ.