简体   繁体   中英

RabbitMq topic exchange

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM