RabbitMQ - Theme Exchanges and Competitive Consumers

I have successfully configured the Exchange theme, and I can immediately send messages to multiple consumers.

I would also like to deliver messages to competing consumers and continue to use topic exchange. I read that using the same queue name allows consumers to compete for messages. Maybe I'm wrong, since I can't get it to work.

Setting up for multiple listeners in the same topic:

  • Announce topic exchange
  • For each listener, declare a new queue with an auto-generated name.
  • Associate this queue with the above exchange with a given topic routing key

How to set competing consumers on the same topic?

Is this possible with tag exchange?

Thanks.

+1
source share
2 answers

I solved this using exchange bindings to exchange.

  • An external exchange is an exchange of topics.
  • An internal exchange is a branching exchange associated with a client queue.
  • An external exchange is tied to an internal exchange using a routing key that includes a wildcard.
0
source

Consider first a couple of points.

First, remember that in RabbitMQ you always consume from queues. Exchange is just your portals, and you cannot directly consume them.

Secondly, Volume Sharing allows you to bind queues using routing โ€œpatternsโ€. Therefore, the term topic is valid in the context of Tag Exchange.

Now this is what I understand from your question:

Multiple consumers / one routing key : Here you want all consumers to consume all messages with the same routing key (or the same routing key patterns in case of tag exchange). It really is doable. Just do the following:

  • Declaring Your Exchange Theme
  • Declare a queue with a name
  • Bind this queue to your topic using the desired routing key template.
  • Create multiple users and ask them to listen to the same queue.

What will happen is that RabbitMQ will load balance to your consumers in a circle. This means that all consumers will consume from the same queue. But remember that in this scenario it is possible that one message is transmitted more than once in theory.

What you did was create multiple queues and have one user in the queue. This means that each message arriving at the exchange will be duplicated in all queues. The end result will be that the message is processed several times.

+3
source

All Articles