Rabbitmq retrieve multiple messages using single synchronous call

后端 未结 4 1275
灰色年华
灰色年华 2021-02-13 19:04

Is there a way to receive multiple message using a single synchronous call ?

When I know that there are N messages( N could be a small value less than 10) in the queue,

4条回答
  •  迷失自我
    2021-02-13 19:52

    Not an elegant solution and does not solve making multiple calls but you can use the MessageCount method. For example:

      bool noAck = false;
      var messageCount = channel.MessageCount("hello");
      BasicGetResult result = null;
      if (messageCount == 0)
      {
          // No messages available
      }
      else
      {
          while (messageCount > 0)
          {
              result = channel.BasicGet("hello", noAck);
              var message = Encoding.UTF8.GetString(result.Body);
              //process message .....
              messageCount = channel.MessageCount("hello");
          }
    

提交回复
热议问题