Rabbitmq Exchange and its Types
Definition
exchange
Message routing agents.
Messages are not published directly to a queue. Instead, the publisher sends messages to an exchange.
Defined by the virtual host within RabbitMQ.
Predefined default exchanges are created at server starts.
Clients can create their own exchanges.
Exchange parameters:
- type
- name
- durability
- auto-delete (once last bound object is unbound from the exchange)
binding
Link between an exchange and a queue.
Use message attributes: routing key, header to route to the messages to queue(s).
Exchange Types
default exchange
No name. (usually referred by an empty string)
Every queue is automatically bound to the default exchange.
Binding key will be the queue name.
direct exchange
Similar to default exchange, but got a name and the bindings are not created automatically.
A message goes to the queue(s) with the binding key that exactly matches the routing key of the message.
fanout exchange
Routing key doesn’t have any effect.
Route message to all queues.
topic exchange
Similar to direct exchange, but use binding pattern not binding key.
A message goes to the queue(s) with the binding pattern that matches the routing key of the message.
header exchange
Similar to direct exchange, but use message header not routing key; use binding header not binding key
If x-match=all, then all header attributes should match
If x-match=any, then any header attributes match counts