1
votes

How do you get the count of dead letter messages in an Azure Service Bus queue?

I can get the count in the queue like so ...

var ns = NamespaceManager.CreateFromConnectionString(sbConnectionString);
var queue = ns.GetQueue(queueName);
var count = queue.MessageCount;

But this looks to include both messages in the queue, and also messages in the associated dead letter queue

How can I differentiate between them?

1

1 Answers

4
votes

Do take a look at MessageCountDetails property in QueueDescription. You will find DeadletterMessageCount there which will provide you the information you're looking for.

var ns = NamespaceManager.CreateFromConnectionString(sbConnectionString);
var queue = ns.GetQueue(queueName);
var count = queue.MessageCount;
var deadletterMessagesCount = queue.MessageCountDetails.DeadletterMessageCount;