How to peek the deadletter messages

前端 未结 4 1156
耶瑟儿~
耶瑟儿~ 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:19

    Here is an example of how you can get a list of all messages in the dead letter queue using Peek:

    public async Task<IEnumerable<BrokeredMessage>> GetDeadLetterMessagesAsync(string connectionString,
        string queueName)
    {
        var queue = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(queueName));
        var messageList = new List<BrokeredMessage>();
        BrokeredMessage message;
        do
        {
            message = await queue.PeekAsync();
            if (message != null)
            {
                messageList.Add(message);
            }
        } while (message != null);
        return messageList;
    }
    
    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
  • 2021-01-16 14:31
    string connectionString = ConfigurationManager.AppSettings["connectionString"];    
    string queueName = ConfigurationManager.AppSettings["queueName"];    
    ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(connectionString);    
    MessagingFactory factory = MessagingFactory.CreateFromConnectionString(builder.ToString());    
    var client = QueueClient.CreateFromConnectionString(connectionString, queueName);    
    string deadLetterQueuePath = QueueClient.FormatDeadLetterPath(queueName);    
    QueueClient deadletterQueueClient = factory.CreateQueueClient(deadLetterQueuePath);    
    while (true)    
    {    
           BrokeredMessage brokeredMessage = deadletterQueueClient.Receive();    
           // Your Logic    
    }
    
    0 讨论(0)
  • 2021-01-16 14:34

    The Azure portal now offers a service bus explorer (preview) tool to perform basic operations (such as Send, Receive, Peek) on Queues/Topics and their dead-letter subentities, right from the portal itself. Check this link on detailed instructions about using this tool - azure-service-bus-messaging-explorer.

    For using more advanced features such as import/export functionality or the ability to test topic, queues, subscriptions, relay services, notification hubs and events hubs, try using the community-owned operations support system (OSS) tool service bus explorer. As on today, you can only peek 32 messages on the preview version of service bus explorer on Azure portal. So, if you have more messages to deal with, then you might want to opt for the above said standalone community-owned OSS tool.

    0 讨论(0)
提交回复
热议问题