First of all, I know there is already an answer to a similar question here, but I am still not sure this is because of RabbitMQ's impossibility or because I haven't researched enough.
I come from JS/Node background where event pub/sub pattern works like this: when many consumers subscribe to the same topic with pub/sub pattern, all of them should get the same message whenever some producer publishes it.
I expect to implement the same pattern with a message broker.
For example:
Consumer 1 listens to 'request.user.#'
Consumer 2 listens to 'request.user.#'
Consumer 3 listens to 'request.#.#'
Producer 1 publishes to topic 'request.user.add'
Producer 2 publishes to topic 'request.user.detail'
What RabbitMQ actually does (according to this RabbitMQ example about Topics)
Consumer 3
gets both messages, while either Consumer 1
or Consumer 2
gets the first message, and only either of them gets the second message.
What I expect to implement
Three of them gets both messages.
Do you have any idea to implement this with a message broker (RabbitMQ in top priority)? Please point out if I miss something or am not clear somewhere in my question.
Thanks in advance.
EDIT with SOLUTION:
Thanks to @cantSleepNow, here is the code (NodeJS) for Consumer 1
and Consumer 2
that I have come up with after his hint:
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', (err, conn) => {
conn.createChannel((err, ch) => {
var ex = 'topic_exchange'; // Exchange name
ch.assertExchange(ex, 'topic'); // Exchange with 'topic' type
ch.assertQueue('', {exclusive: true}, (err, q) => {
ch.bindQueue(q.queue, ex, 'request.user.#'); // Topic pattern
ch.consume(q.queue, (msg) => {
// Process message
});
});
});
});