Reputation: 10179
We are rebuilding our message queue system. While going over the RabbitMQ exchange types, I noticed there are two potential solutions to implement the multi-cast nature of routing messages.
Topic Exchange. By setting up a topic exchange and a routing key with specific pattern, message would be routed to the designated queues. I.E. products.*. According to the AMQP spec, this is usually the exchange type to implement Pub/Sub pattern.
Header Exchange. The so-called "Direct Exchange on Steroids". It's even more flexible to multi-cast messages in that routing key is ignored, instead each message has "x-match" header to denote which queues the message is supposed to be delivered to. And each message can be dynamically routed differently. However, this exchange type may seems a bit more tightly coupled with the Message Queue design as the consumer / producer would have to know more about the destination queues.
So the question is, has anyone experienced with both exchange types and share more characteristics of the pros/cons for the above two types? Thanks!
Reference [1]: https://www.rabbitmq.com/tutorials/amqp-concepts.html
Upvotes: 16
Views: 15856
Reputation: 2374
If your routing decisions are based on a single value e.g. routing_key
, then Topic Exchange would satisfy that with better performance.
If your routing decisions require multiple values then Headers Exchange would allow you to do that. It can also match ANY
of these values or ALL
.
Upvotes: 0
Reputation: 10358
Both of the exchange implement different routing algorithm.
Topic Exchange
:
Headers Exchange
:
Upvotes: 3
Reputation: 459
I have worked with both header and topic exchange, in my experience header exchange is more flexible but while sending message through code, which we usually does, it is easy to use topic exchange because of regular expression type syntax.
You can read more about this here :
http://codedestine.com/rabbitmq-headers-exchange/
http://codedestine.com/rabbitmq-topic-exchange/
Upvotes: 8