Search code examples
c#azureazureservicebusazure-servicebus-queues

How do you delete the dead letters in an Azure Service Bus queue?


How do you delete the dead letters in an Azure Service Bus queue?

I can process the messages in the queue ...

var queueClient = QueueClient.CreateFromConnectionString(sbConnectionString, queueName);
while (queueClient.Peek() != null)
{
    var brokeredMessage = queueClient.Receive();
    brokeredMessage.Complete();
}

but can't see anyway to handle the dead letter messages


Solution

  • The trick is to get the deadletter path for the queue which you can get by using QueueClient.FormatDeadLetterPath(queueName).

    Please try the following:

    var queueClient = QueueClient.CreateFromConnectionString(sbConnectionString, QueueClient.FormatDeadLetterPath(queueName));
    while (queueClient.Peek() != null)
    {
        var brokeredMessage = queueClient.Receive();
        brokeredMessage.Complete();
    }