1

I have producer app with 2 separate instances (p1, p2), and consumer app with 2 separate instances (c1, c2).

Producer p1 connects to exchange with topic= t1, queueName =name1.

Consumer c1 connects to exchange with topic= t1, queueName =name1.

Producer p2 connects to exchange with topic= t2, queueName =name1.

Consumer c2 connects to exchange with topic= t2, queueName =name1.

I see in RabbitMQ GUI that I have 2 exchanges but only 1 queue. Instead that c1 will receive messages from p1 only, and c2 will receive messages from p2 only, RabbitMQ is doing round robin on messages between c1 and c2. So the messages I send from p2 are being received both by c1 and c2.

I thought that in RabbitMQ the correlation is multiple queues per exchange, and the behavior here is unexpected. Why?

KerenSi
  • 389
  • 7
  • 20

1 Answers1

4

You can have multiple queues for every exchange, it's true; but the routing key is a queue matter, not a consumer matter.

The routing key will be used by rabbit to send the message to the right queue; once the message is received on a topic exchange, the message will be sent to all the queues binded to that specific topic. You have only one queue here, that's why both C1 and C2 get the message.

Check this link for a clear example.

enter image description here

If you need to separate C1 and C2, you need to bind them to 2 different queues, not to the same one.

Luca Ghersi
  • 3,261
  • 18
  • 32
  • 1
    In this diagram there is only 1 producer, I have 2 producers and 2 exchanges. If you look at my problem from a deffierent aspect, I have a consumer that receive requests from 2 producers. How can it be possible? – KerenSi Apr 20 '16 at 14:28
  • Because you're using the same queue for both your consumers; if you have two exchanges binded to the same queue, no matter who produced the message, it will be sent to the queue "queueName =name1" and both your consumer will see it. – Luca Ghersi Apr 20 '16 at 15:02