簡體   English   中英

如何從服務總線死信隊列中讀取消息?

[英]How to read the message from the service bus dead-letter queue?

如何從服務總線死信隊列中讀取消息? 我能夠讀取消息 ID 和消息的序列號,但我需要實際消息。 有人可以幫我弄這個嗎? 是否可以閱讀實際消息?

在讀取消息表單死信隊列之前,您應該檢查失敗的原因是什么? 如果某些服務不可用,則創建 WebJob 並嘗試以下代碼並處理消息。

public void GetDeadLetterMessagesAsync(string connectionString, string queueName)
    {
        var queueClient = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(queueName));
        while (true)
        {
            BrokeredMessage bmessgage = queueClient.Receive();
            if (bmessgage != null)
            {
                string msg = new StreamReader(bmessgage.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();
                //Custom business logic to prcess your message
                bmessgage.Complete();
            }
            else
            {
                break;
            }
        }
    }

如果消息有問題,那么您應該閱讀並在 UI 上顯示消息,以便后台團隊可以更正消息,否則它將再次失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM