Clearing azure service bus queue in one go(一次性清除 Azure 服务总线队列)
问题描述
我们在项目中使用服务总线队列.当管理员选择清除队列时,我们需要一个从队列中删除所有消息的功能.我在网上搜索,但找不到在 QueueClient 类中执行此操作的任何函数.
We are using a service bus queue in our project. We are in need of a functionality to remove all the messages from the queue when the administrator chooses to clear the queue. I searched on the net but could not find any function which does this inside the QueueClient class.
我是否必须将所有消息一一弹出,然后将它们标记为完成以清除队列,还是有更好的方法?
Do I have to pop all the messages one by one and then marking them complete to clear the queue or is there a better way?
QueueClient queueClient = _messagingFactory.CreateQueueClient(
queueName, ReceiveMode.PeekLock);
BrokeredMessage brokeredMessage = queueClient.Receive();
while (brokeredMessage != null )
{
brokeredMessage.Complete();
brokeredMessage = queueClient.Receive();
}
推荐答案
您可以简单地从 azure 门户中执行此操作.
You can simply do this from azure portal.
如果您不担心过去 14 天(默认)存储的队列消息并想立即清除队列,则将消息时间更改为 5 或 10 秒并等待 5-10 秒.
If you are not worried about queue messages stored in past 14 days (default) and wanted to clear queue immediately then change message time to live value to 5 or 10 seconds and wait for 5-10 seconds.
重要步骤:几秒钟后,尝试从队列中接收以强制更新.
Important step: After a few seconds, try to receive from queue to force it to update.
所有队列消息将被清除.您可以再次重置原始值.默认为 14 天.
All queue messages will be cleared. you can again reset original value. default is 14 days.
这篇关于一次性清除 Azure 服务总线队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:一次性清除 Azure 服务总线队列
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
