In RabbitMQ how to consume multiple message or read all messages in a queue or all messages in exchange using specific key?

て烟熏妆下的殇ゞ 提交于 2020-01-05 12:08:23

问题


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

so the scenario is as follow:

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.

I also read this post:

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

Thanks


回答1:


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. :)



来源:https://stackoverflow.com/questions/22647268/in-rabbitmq-how-to-consume-multiple-message-or-read-all-messages-in-a-queue-or-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!