Clear the Dead Letter messages from an Azure Service Bus Queue

Sometimes we may have a situation to read the message from Dead Letter Queue to know which message are not processed and we may re-queue them if required. In such situations, we can read the messages from the Dead Letter Queue of an Azure Service Bus Queue in the same manner as we connect to the normal queue, but we need to post fix "$DeadLetterQueue" to the queue name.
Following is the code snippet for reading / clearing the messages from Dead Letter Queue.
using Microsoft.ServiceBus.Messaging;

 string serviceBusConnString = "****** Your Service bus Connection String ******";
 string queueName = "Your Queue name" + "/$DeadLetterQueue";  // for dead letter queue.

 QueueClient client = QueueClient.CreateFromConnectionString(serviceBusConnString, queueName, ReceiveMode.PeekLock);
 while (client.Receive() != null)
     var deadMessage = client.Receive();
     //do something here with the message if required.


    Blogger Comment
    Facebook Comment


Post a Comment