How to peek the deadletter messages

前端 未结 4 1180
耶瑟儿~
耶瑟儿~ 2021-01-16 14:14

It is very hard to find some good documentation on getting all the messages in a deadletter queue and getting to take a peek at them.

I have an Azure Servicebus Que

4条回答
  •  温柔的废话
    2021-01-16 14:27

    Dead letter queue is a secondary sub-queue where the poison messages are moved to.

    In case of Azure Servicebus Queue the standard path for DLQ is queuePath/$DeadLetterQueue. So you need to have another queueClient to read the DLQ.

    And you will do something like this in .NET clients.

    string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
    var client = QueueClient.CreateFromConnectionString(connectionString, "QueueName");
    
    // do whatever regular queue reading activities
    
    // this is for dead letter queue
    var deadLetterClient = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(client.Path), ReceiveMode.ReceiveAndDelete);
    
    BrokeredMessage receivedDeadLetterMessage;
    while ((receivedDeadLetterMessage = deadLetterClient.Receive(TimeSpan.FromSeconds(10))) != null)
    {
        Console.WriteLine(receivedDeadLetterMessage);
    }
    

提交回复
热议问题