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

简介: 【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 = "<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

相关文章
|
6月前
|
缓存 API Windows
【服务总线 Azure Service Bus】Service Bus在使用预提取(prefetching)后出现Microsoft.Azure.ServiceBus.MessageLockLostException异常问题
【服务总线 Azure Service Bus】Service Bus在使用预提取(prefetching)后出现Microsoft.Azure.ServiceBus.MessageLockLostException异常问题
|
6月前
【Azure 事件中心】Azure Event Hub客户端遇见 Expired Heartbeat 错误
【Azure 事件中心】Azure Event Hub客户端遇见 Expired Heartbeat 错误
|
4月前
|
内存技术
【Azure Cloud Service】创建Azure云服务时遇见分配VM资源错误: VM(s) with the following constraints cannot be allocated, because the condition is too restrictive
Allocation failed. VM(s) with the following constraints cannot be allocated, because the condition is too restrictive. Please remove some constraints and try again. Constraints applied are:\n - VM Size
|
5月前
【Azure Service Bus】批量处理Service Bus Topic 中的死信消息(dead-lettered messages)
当然是有的。就是Service Bus Explorer工具,下载ZIP包解压或者安装版均可! 这个版本提供强大的 Service Bus 的管理功能。
|
6月前
|
程序员
【服务总线 Azure Service Bus】ServiceBus 队列中死信(DLQ - Dead Letter Queue)问题
【服务总线 Azure Service Bus】ServiceBus 队列中死信(DLQ - Dead Letter Queue)问题
|
6月前
|
缓存 Java API
【Azure 服务总线】详解Azure Service Bus SDK中接收消息时设置的maxConcurrentCalls,prefetchCount参数
【Azure 服务总线】详解Azure Service Bus SDK中接收消息时设置的maxConcurrentCalls,prefetchCount参数
|
6月前
|
存储 网络安全 API
【Azure Service Bus】 Service Bus如何确保消息发送成功,发送端是否有Ack机制 
【Azure Service Bus】 Service Bus如何确保消息发送成功,发送端是否有Ack机制 
|
6月前
|
开发工具 Python
【Azure 服务总线】如何批量删除Azure Service Bus中的Topics(数量较多,需要过滤后批量删除)
【Azure 服务总线】如何批量删除Azure Service Bus中的Topics(数量较多,需要过滤后批量删除)
|
6月前
|
网络安全
【Azure Service Bus】启用诊断日志来获取客户端访问Azure Service Bus的IP地址 [2024-03-26 实验结果失败]
【Azure Service Bus】启用诊断日志来获取客户端访问Azure Service Bus的IP地址 [2024-03-26 实验结果失败]
|
6月前
|
消息中间件 开发工具
【Azure 事件中心】Event Hub 消费端出现 Timeout Exception,errorContext中 LINK_CREDIT为0的解释
【Azure 事件中心】Event Hub 消费端出现 Timeout Exception,errorContext中 LINK_CREDIT为0的解释