Search code examples
rabbitmqmq

How do I deliver a message to a one subscriber of each group in RabbitMQ?


Say I have this pub/sub pattern implemented:

enter image description here

So basically I deliver a message to each C, who subscribed to exchange X.

I have instances of P, and a lot subscribers like C. Let's define C10, C11, C12, C13 as a group C1 and C20, C21, C22, C23 as a group C2.

How do I deliver a message so only one C will receive a message from each group? (I'm perfectly fine with round robin)


Solution

  • So appears what I needed was a fanout exchange with named queues instead of exclusive ones.

    enter image description here

    Each C service declares a non-exclusive named queue and binds it to the exchange. And binds a consumer to that queue.

    If two services would declare a same queue, and bind a consumer to it, they end up being round-robin'ed.