0
votes

I'm looking for a way to make hierarchical routing in RabbitMQ. I tried to find the answer in documentation, but suddenly failed.

Generally, RabbitMQ allows you to connect to direct exchanges by some routing key but it is not clear for me how I can route between several exchanges.

For instance, let's say we have 'root' exchange and 'host1' exchange with routing key 'host1'. And I have a queues binded to 'host1' exchange by routing key their own pids. Can I publish message to 'root' exchange with routing_key, like 'host1.31261'? Obviously, it doesn't work exactly that way but is there a way to make a complex route with different direct exchanges?

1

1 Answers

1
votes

yes, you can do this

you can use exchange to exchange bindings for this

you can include routing keys for this binding

the exchange type for both the original and target can be any type you want. need a topic exchange for complex routing? then declare your exchanges as topic.

you can even go from a topic exchange of host to a direct or fanout exchange as the target.

the key is just to declare each exchange as it needs to be declared, before you do the binding.

the examples shown in that documentation include java and .net code. you'll need to check with the library that you are using for your specific language.

in general, though, the same binding for queues works for exchanges. you just need to call the equivalent "bind exchange" method, instead of "bind queue"

if your library doesn't support it, you can manually add the binding via the RabbitMQ management web site.