简体   繁体   English

从队列中读取来自 azure 服务总线的所有消息

[英]Reading all messages from azure service bus from queue

I want to read all messages from azure service bus (queue).我想从 azure 服务总线(队列)读取所有消息。

I have followed instruction from below link https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-php-how-to-use-queues我已按照以下链接https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-php-how-to-use-queues 中的说明进行操作

Currently it fetch one message..目前它获取一条消息..

I want to fetch all messages from service bus(queue).我想从服务总线(队列)中获取所有消息。

Thanks in Advance..提前致谢..

I don't think it is possible to specify the number of messages you wish to read from the queue (at least with PHP SDK, it is certainly possible with .Net SDK).我认为不可能指定您希望从队列中读取的消息数量(至少对于 PHP SDK,使用 .Net SDK 肯定是可能的)。 Essentially receiveQueueMessage is a wrapper over either Peek-Lock Message (Non-Destructive Read) or Receive and Delete Message (Destructive Read) (depending on the configuration) REST API methods and both of them return only a single message.本质上, receiveQueueMessagePeek-Lock Message (Non-Destructive Read)Receive and Delete Message (Destructive Read) (取决于配置)REST API 方法的包装器,并且它们都只返回一条消息。

One way to solve this problem is to run your code in loop till the time you don't receive any message back from the queue.解决此问题的一种方法是循环运行您的代码,直到您没有收到来自队列的任何消息。 The issue that you could possibly run into with this is you may get back duplicate messages as once the lock acquired by peek-lock method is expired, the message will become visible again.您可能遇到的问题是您可能会返回重复的消息,因为一旦 peek-lock 方法获取的锁过期,该消息将再次可见。

Reading all the messages in a Queue is possible with Peek operation concept of Service bus.使用服务总线的Peek操作概念可以读取队列中的所有消息。

MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(<Your_Connection_String>);
var queueClient = messagingFactory.CreateQueueClient(<Your_Queue_Name>, ReceiveMode.PeekLock); // Receive mode is by default PeekLock and hence, optional.
BrokeredMessage message = null;
while(true)
{
  message = queueClient.Peek(); // You have read one message
  if (message == null) // Continue till you receive no message from the Queue
    break; 
}

This can also return expired or locked messages.这也可以返回expiredlocked消息。 Give a quick read about Message browsing if this suits your requirement of reading messages.如果这符合您阅读消息的要求,请快速阅读有关消息浏览的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM