14
votes

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

2
There was talk about headers exchanges in rabbitmq mailing list - lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-January/…, it give more food for you to decide whether to use headers exchange or notpinepain
The x-match header does not go on the message, it goes on the binding (which should be created by your consumers). So its not more tightly coupled in that regard.john16384
I have created a good tutorial on both of these, please have a look jstobigdata.com/rabbitmq/topic-exchange-in-amqp-rabbitmq and jstobigdata.com/rabbitmq/…SyntaX

2 Answers

7
votes

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/

0
votes

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.