问题
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