0
votes

Is it possible to achieve the following scenario using RabbitMQ topic exchange.

Lets say I have two queues:

Queue1: routing key MainRoute.Route1

Queue2: routing key MainRoute.Route2

When I publish my message with routing key:

MainRoute.Route1 -> Queue1

MainRoute.Route2 -> Queue2

MainRoute -> Queue1 and Queue2

Is it possible to achieve this without implementing some special filtering, routing process ?

If not can you please advise on a possible solution for the problem.

Thank you.

1

1 Answers

0
votes

This can be done with a direct or a topic exchange, and would require 4 bindings in your exchange.

Assuming an exchange named "MainEx" as an example, the routing keys would be set up like this:

| exchange | binding          | queue  |
| -------- | ---------------- | ------ |
| MainEx   | MainRoute.Route1 | Queue1 |
| MainEx   | MainRoute.Route2 | Queue2 |
| MainEx   | MainRoute        | Queue1 |
| MainEx   | MainRoute        | Queue2 |

With a topic exchange, you could send multiple messages to a single queue by using flags. For example, binding "MainRoute.#" to "Queue3" would send all MainRoute messages to Queue3.

But, there is no way to do the opposite with a single binding. You need to create multiple bindings to do what you want.