ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【Azure 服务总线】Azure Service Bus中私信(DLQ - Dead Letter Queue)如何快速清理

2021-03-04 12:01:24  阅读:212  来源: 互联网

标签:私信 Service 队列 Bus 死信 Azure processor


在博文ServiceBus 队列中死信(DLQ - Dead Letter Queue)问题一文中,介绍了服务总线产生私信的原因及可以通过代码的方式来清楚私信队列中的消息,避免长期占用空间(因为私信中的消息不会自动清理)

当前,我们也可以从Azure门户中查看到当前DLQ的数量,所占空间及进入DLQ的原因

问题描述

在使用Azure Service Bus过程中,随着时间的累积,当死信中存积了大量的消息时,如何快速的清理掉这些消息呢?

 

解决办法

使用Azure官方提供的工具 Service Bus Explorer。 连接到当前的Service Bus,通过选择Receive and Delete操作来获取并从Service Bus服务端中删除消息。

1) 下载Service Bus Explorer,解压文件后,双击ServiceBusExplorer.exe

 

2) 连接到Service Bus中并查看死信消息

3) Receive and Delete: 数据获取消息的数量,然后再Receive Mode中选择Receive and Delete

 

 

附录:另一种方式是通过代码来处理死信消息

如需要通过程序的方式获取死信队列中的消息,获取消息的方式和正常队列一样,把queueName变为死信队列的路径,通过QueueClient.FormatDeadLetterPath(queueName)方式获取

 

附上.NET伪代码:

    static string queueName = "<QUEUE NAME>/$deadletterqueue";


    static async Task ReceiveMessagesAsync()
    {
        await using (ServiceBusClient client = new ServiceBusClient(connectionString))
        {
            // create a processor that we can use to process the messages
            ServiceBusProcessor processor = client.CreateProcessor(queueName, new ServiceBusProcessorOptions());

            // add handler to process messages
            processor.ProcessMessageAsync += MessageHandler;

            // add handler to process any errors
            processor.ProcessErrorAsync += ErrorHandler;

            // start processing 
            await processor.StartProcessingAsync();

            Console.WriteLine("Wait for a minute and then press any key to end the processing");
            Console.ReadKey();

            // stop processing 
            Console.WriteLine("\nStopping the receiver...");
            await processor.StopProcessingAsync();
            Console.WriteLine("Stopped receiving messages");
        }
    }

 

参考资料

从队列接收消息https://docs.azure.cn/zh-cn/service-bus-messaging/service-bus-dotnet-get-started-with-queues#receive-messages-from-a-queue
Azure Service Bus 死信队列产生的原因https://www.cnblogs.com/lulight/p/13652828.html
Azure Service Bus Explorer: https://github.com/paolosalvatori/ServiceBusExplorer/releases

 

标签:私信,Service,队列,Bus,死信,Azure,processor
来源: https://www.cnblogs.com/lulight/p/14479211.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有