清除蔚蓝服务总线队列一气呵成 [英] Clearing azure service bus queue in one go
问题描述
我们在我们的项目中使用服务总线队列。我们需要的功能,从队列中删除所有邮件管理员选择以清除队列。我在网上搜索,但没有找到它做到这一点的 QueueClient
类中的任何功能。
我一定要弹出所有的消息一个接一个,然后将它们标记完全清除队列或是否有更好的办法吗?
QueueClient queueClient = _messagingFactory.CreateQueueClient(
queueName,ReceiveMode.PeekLock);
BrokeredMessage brokeredMessage = queueClient.Receive();
而(brokeredMessage!= NULL)
{
brokeredMessage.Complete();
brokeredMessage = queueClient.Receive();
}
有关Azure的ServiceBus-队列存在的 ReceiveBatch
-method ,让您能够接收一批的 N 的-messages的时间。结合 ReceiveMode.ReceiveAndDelete
您可以更有效地清除队列。
买者的数量的的消息正的可能会返回,但它不能保证。也有对 256K 的消息批次大小的限制
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();
}
For Azure-ServiceBus-Queues there is a ReceiveBatch
-method which allows you to receive a batch of n-messages at the time. Combined with ReceiveMode.ReceiveAndDelete
you can clear the queue more efficiently.
Caveat The number n of messages might be returned but it's not guaranteed. Also there is a limit for the message-batch size of 256K.
这篇关于清除蔚蓝服务总线队列一气呵成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!