How to peek the deadletter messages

前端 未结 4 1157
耶瑟儿~
耶瑟儿~ 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> GetDeadLetterMessagesAsync(string connectionString,
        string queueName)
    {
        var queue = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(queueName));
        var messageList = new List();
        BrokeredMessage message;
        do
        {
            message = await queue.PeekAsync();
            if (message != null)
            {
                messageList.Add(message);
            }
        } while (message != null);
        return messageList;
    }
    

提交回复
热议问题