问题描述
我们在项目中使用服务总线队列.当管理员选择清除队列时,我们需要一个从队列中删除所有消息的功能.我在网上搜索,但找不到在 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 服务总线队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!