【Azure 服务总线】Azure Service Bus中私信(DLQ - Dead Letter Queue)如何快速清理
在博文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 = 1f32 "<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
- Azure Service Bus(二)在NET Core 控制台中如何操作 Service Bus Queue
- 【服务总线 Azure Service Bus】Service Bus在使用预提取(prefetching)后出现Microsoft.Azure.ServiceBus.MessageLockLostException异常问题
- 如何在 Linux 中快速地通过 HTTP 提供文件访问服务 | Linux 中国
- 【Azure 应用服务】Azure App Service (Windows) 使用Flask框架部署Python应用,如何在代码中访问静态文件呢?如何设置文件路径?是相对路径还是绝对路径呢?
- How To Automate Cleanup Of Dead Connections And INACTIVE 【如何自动清理ORACLE中的死连接和非活动会话】
- DELL服务器如何在服务器/存储设备的操作系统下快速获取主机的服务编号
- 如何快速修改web服务的端口号和应用名
- 如何快速搭建一个微服务架构-咕泡学院Java架构VIP试听视频
- 如何在 Linux 中快速地通过 HTTP 提供文件访问服务
- 如何快速清理Exchange Server的SMTP队列
- [置顶] 浅析如何快速有效地卸载删除电脑上多余的tomcat6.7.8.9服务
- 教你如何快速的在linux5.0上为大型公司企业搭建DHCP(动态主机配置)服务以及中继代理服务
- ESB(Enterprise Service Bus,即企业服务总线)
- 如何快速将Linux文件系统迁移到Azure存储
- windows azure Vm、cloud service、web application 如何选择可用的服务
- 【Azure 云服务】Azure Cloud Service在发布新部署后遇见不能RDP(远程连接)到实例时如何处理?
- 如何通过本地化事件正确实现微服务内部强一致性,事件总线跨微服务间最终一致性
- 如何通过本地化事件正确实现微服务内部强一致性,事件总线跨微服务间最终一致性
- 探索企业服务总线:了解 ESB 如何帮助您满足 SOA 解决方案的需求
- 如何快速地在上千台服务器上部署一项服务