Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ Exchange Type comparison: Topic vs. Header

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.

  1. 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.

  2. 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

like image 708
Devy Avatar asked Jun 09 '14 21:06

Devy


1 Answers

Both of the exchange implement different routing algorithm.

Topic Exchange:

  • It will allow us to selectively route messages based upon wildcard matching in the routing key.
  • effective performance

Headers Exchange:

  • It allows you to match against a header in the AMQP message instead of the routing key.
  • It operates identically to the direct exchange but with much worse performance. As a result, it doesn’t provide much real-world benefit.
like image 123
Gupta Avatar answered Sep 28 '22 19:09

Gupta