Do messages in dead letter queues in Azure Service Bus expire?
I have these queue settings:
var queueDescription = new QueueDescription("MyTestQueue")
{
RequiresSession = false,
DefaultMessageTimeToLive = TimeSpan.FromMinutes(1),
EnableDeadLetteringOnMessageExpiration = true,
MaxDeliveryCount = 10
};
namespaceManager.CreateQueue(queueDescription);
When I place some messages in a Azure Service Bus message queue (not queues from Azure Storage) and don't consume them (ever), they'll be moved to the dead letter queue automatically.
However, if I have no consumer for the dead letter queue either, will the messages ever be deleted from the dead letter queue or will they stay there forever? (Is there some official documentation stating how this is supposed to work?)
In my trials, I placed 3 messages in the queue. They were dead lettered after 2 minutes or so. They remained in the dead letter queue for at least a day and weren't removed.
Although calling NamespaceManager.GetQueueAsync() gave me the values above (notice how MessageCount
is still 3
but DeadLetterMessageCount
is strangely 0
), I could still receive the messages from the dead letter queue. (So they weren't removed from the queue.)
By default, the message lock expires after 60 seconds. This value can be extended to 5 minutes.
As mentioned before all your expired messages will be moved to the dead-letter queue of your queue and sit there until you process them.
Azure Service Bus Architecture Queues store incoming messages until the receiving application is available to receive and process them.
Sebastian your observation is correct, in that messages once placed in the DeadLetter sub-queue never expire. They will be available there forever until removed explicitly from the DeadLetter sub-queue. In the above error regarding the tooling/api it could be a refresh issue? The call to GetQueueAsync() needs to be made after the messages have been dead-lettered which is not a deterministic time, say if you had a queue with a thousand messages that were expired but that Queue was not being used (send/receive operations) then the count may still return as Active until some operations are performed.
After doing some research I stumbled over a fact I missed completely:
Messages can expire even when dead lettering is disabled.
When messages expire while dead lettering is disabled (which is the default), they'll just get deleted.
So, Microsoft's reasoning for not auto-deleting messages from the dead letter queue is probably:
If you're enabling dead lettering, you explicitly want expired message not to be thrown away but stored somewhere else (the dead letter queue) so that you can review them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With