Notifying all consumers of a message

394 Views Asked by At

We are using Rebus 4.2.1 and RabbitMQ

What we want to achieve is to have handlers on three (or more) instances all react to the same message.

As far as I understood (which may be wrong) - .Publish on the IBus interface should do exactly that (and we have been running with that on MSMQ).

Is there something I am missing with how RabbitMQ works?

(EDIT: I think the term used in RabbitMQ is a "fanout" style message)

EDIT2: mookid8000 put me on the right track - the issue was that each replica was asking for the same queue. As soon as I made that unique - everything started working as intended (and expected).

1

There are 1 best solutions below

6
On BEST ANSWER

With Rebus + RabbitMQ, it's pretty simple, because RabbitMQ has native support for topic-based pub/sub messaging.

In each subscriber, you simply call

await bus.Subscribe<YourEvent>();

which will make Rebus generate a topic string out of your event type, and then bind it to the subscriber's input queue, and then in the publisher you

await bus.Publish(new YourEvent(...));

and then each subscriber will get a copy of the event in its input queue.

Underneath the covers, Rebus uses RabbitMQ's "Topic Exchange" exchange type to make this work.