RabbitMQ / AMQP: single queue, multiple consumers for same message?

前端 未结 12 2283
不思量自难忘°
不思量自难忘° 2020-11-28 00:53

I am just starting to use RabbitMQ and AMQP in general.

  • I have a queue of messages
  • I have multiple consumers, which I would like to do different thing
12条回答
  •  被撕碎了的回忆
    2020-11-28 01:59

    As I assess your case is:

    • I have a queue of messages (your source for receiving messages, lets name it q111)

    • I have multiple consumers, which I would like to do different things with the same message.

    Your problem here is while 3 messages are received by this queue, message 1 is consumed by a consumer A, other consumers B and C consumes message 2 and 3. Where as you are in need of a setup where rabbitmq passes on the same copies of all these three messages(1,2,3) to all three connected consumers (A,B,C) simultaneously.

    While many configurations can be made to achieve this, a simple way is to use the following two step concept:

    • Use a dynamic rabbitmq-shovel to pickup messages from the desired queue(q111) and publish to a fanout exchange (exchange exclusively created and dedicated for this purpose).
    • Now re-configure your consumers A,B & C (who were listening to queue(q111)) to listen from this Fanout exchange directly using a exclusive & anonymous queue for each consumer.

    Note: While using this concept don't consume directly from the source queue(q111), as messages already consumed wont be shovelled to your Fanout exchange.

    If you think this does not satisfies your exact requirement... feel free to post your suggestions :-)

提交回复
热议问题