RabbitMQ Exchange Type comparison: Topic vs. Header
Asked Answered
N

3

15

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

Newhall answered 9/6, 2014 at 21:57 Comment(0)
T
8

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/

Treaty answered 10/2, 2017 at 11:19 Comment(0)
D
2

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.
Dote answered 11/3, 2021 at 14:1 Comment(0)
H
0

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.

Heidi answered 25/5, 2023 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.