Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do messages in dead letter queues in Azure Service Bus expire?

Do messages in dead letter queues in Azure Service Bus expire?

Some explanation

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?)

My Trials

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.

Message Queue Statistics

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.)

like image 876
Sebastian Krysmanski Avatar asked May 13 '14 09:05

Sebastian Krysmanski


People also ask

What is message lock duration in Azure Service Bus?

By default, the message lock expires after 60 seconds. This value can be extended to 5 minutes.

Where are the expired messages in queues stored?

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.

Does Azure Service Bus store messages?

Azure Service Bus Architecture Queues store incoming messages until the receiving application is available to receive and process them.


2 Answers

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.

like image 53
Abhishek Lal Avatar answered Oct 22 '22 01:10

Abhishek Lal


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.

like image 4
Sebastian Krysmanski Avatar answered Oct 22 '22 01:10

Sebastian Krysmanski