Rabbitmq 使用单个同步调用检索多条消息 [英] Rabbitmq retrieve multiple messages using single synchronous call

查看:47
本文介绍了Rabbitmq 使用单个同步调用检索多条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用单个同步调用接收多条消息?

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

当我知道队列中有 N 条消息(N 可能是小于 10 的小值)时,我应该能够执行类似 channel.basic_get(String queue, boolean autoAck, int numberofMsg ) 的操作.我不想向服务器发出多个请求.

When I know that there are N messages( N could be a small value less than 10) in the queue, then I should be able to do something like channel.basic_get(String queue, boolean autoAck , int numberofMsg ). I don't want to make multiple requests to the server .

推荐答案

RabbitMQ 的 basic.get 不幸的是不支持多条消息 如文档中所示.检索多条消息的首选方法是使用 basic.consume 将消息推送到客户端,避免多次往返.acks 是异步的,因此您的客户端不会等待服务器响应.basic.consume 还具有允许 RabbitMQ 在客户端断开连接时重新传递消息的好处,这是 basic.get 无法做到的.这也可以关闭,也可以将 no-ack 设置为 true.

RabbitMQ's basic.get doesn't support multiple messages unfortunately as seen in the docs. The preferred method to retrieve multiple messages is to use basic.consume which will push the messages to the client avoiding multiple round trips. acks are asynchronous so your client won't be waiting for the server to respond. basic.consume also has the benefit of allowing RabbitMQ to redeliver the message if the client disconnects, something that basic.get cannot do. This can be turned off as well setting no-ack to true.

设置basic.qos prefetch-count 将设置随时推送给客户端的消息数量.如果客户端没有等待消息(会立即返回),客户端库往往会因可选超时而阻塞.

Setting basic.qos prefetch-count will set the number of messages to push to the client at any time. If there isn't a message waiting on the client side (which would return immediately) client libraries tend to block with an optional timeout.

这篇关于Rabbitmq 使用单个同步调用检索多条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆