Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scenarios where to use which type of exchange(direct, fanout, topic, headers) in RabbitMQ?

I am not able to figure out the actual scenarios of using different exchange types provided in RabbitMQ.

like image 737
Badal Avatar asked Dec 25 '22 20:12

Badal


2 Answers

Exchange is entity defined in AMQP protocol. See AMQP concepts at RabbitMQ tutorial:

  • A direct exchange delivers messages to queues based on the message routing key. A direct exchange is ideal for the unicast routing of messages.

  • A fanout exchange routes messages to all of the queues that are bound to it and the routing key is ignored. Fanout exchanges are ideal for the broadcast routing of messages. Massively multi-player online (MMO) games can use it for leaderboard updates or other global events; Sport news sites can use fanout exchanges for distributing score updates to mobile clients in near real-time; Distributed systems can broadcast various state and configuration updates; Group chats can distribute messages between participants using a fanout exchange (although AMQP does not have a built-in concept of presence, so XMPP may be a better choice).

  • Topic exchanges route messages to one or many queues based on matching between a message routing key and the pattern that was used to bind a queue to an exchange. Example uses: Distributing data relevant to specific geographic location, for example, points of sale; Background task processing done by multiple workers, each capable of handling specific set of tasks; Stocks price updates (and updates on other kinds of financial data); News updates that involve categorization or tagging (for example, only for a particular sport or team); Orchestration of services of different kinds in the cloud; Distributed architecture/OS-specific software builds or packaging where each builder can handle only one architecture or OS.

  • A headers exchange is designed for routing on multiple attributes that are more easily expressed as message headers than a routing key. Headers exchanges can be looked upon as "direct exchanges on steroids". Because they route based on header values, they can be used as direct exchanges where the routing key does not have to be a string; it could be an integer or a hash (dictionary) for example.

like image 135
flam3 Avatar answered Dec 27 '22 09:12

flam3


See the rabbitmq tutorials for examples.

like image 38
Gary Russell Avatar answered Dec 27 '22 10:12

Gary Russell