在RabbitMQ中,如何使用多条消息使用多条消息或读取队列中的所有消息,或者交换所有消息以使用特定密钥? [英] In RabbitMQ how to consume multiple message or read all messages in a queue or all messages in exchange using specific key?

查看:325
本文介绍了在RabbitMQ中,如何使用多条消息使用多条消息或读取队列中的所有消息,或者交换所有消息以使用特定密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用给定密钥从特定队列或特定交换中消耗多条消息.

I want to consume multiple messages from specific queue or a specific exchange with a given key.

因此情况如下:

发布者在队列1上发布消息1 发布者在队列1上发布消息2 发布者在队列1上发布消息3 发布者在队列2上发布消息4 发布者在队列2上发布消息5 .. 使用者使用队列1中的消息 同时获得[消息1,消息2,消息3],并在一次回叫中处理它们

Publisher publish message 1 over queue 1 Publisher publish message 2 over queue 1 Publisher publish message 3 over queue 1 Publisher publish message 4 over queue 2 Publisher publish message 5 over queue 2 .. Consumer consume messages from queue 1 get [message 1, message 2, message 3] all at once and handle them in one call back

listen_to(queue_name , num_of_msg_to_fetch or all, function(messages){
//do some stuff with the returned list
});

消息不是同时发出的,就像事件一样,我想将它们收集在队列中,打包并发送给第三方.

the messages are not coming at the same time, it is like events and i want to collect them in a queue, package them and send them to a third party.

我也阅读了这篇文章:

http://rabbitmq. 1065348.n5.nabble.com/Consuming-multiple-messages-at-a-time-td27195.html

谢谢

推荐答案

当队列遵循轮询算法(AMQP要求)时,不要直接从队列中使用 使用铲将队列内容传输到扇出交换机,并直接从此交换机使用消息.您会在所有连接的使用者之间获得所有消息. :)

Don't consume directly from the queue as queues follow round robin algorithm(an AMQP mandate) Use shovel to transfer the queue contents to a fanout exchange and consume messages right from this exchange. You get all messages across all connected consumers. :)

这篇关于在RabbitMQ中,如何使用多条消息使用多条消息或读取队列中的所有消息,或者交换所有消息以使用特定密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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