Pergunta

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

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top