We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Types of Exchanges

RabbitMQ supports several types of exchanges, each serving a different routing strategy.

In my experience, direct and topic are the most commonly useful in backend Pub/Sub architectures. I rarely have a use for sending all messages to all queues, or for routing based on the message headers.

We'll talk more about the intricacies of routing keys later.

Breakdown

  • Direct: Messages are routed to the queues based on the message routing key exactly matching the binding key of the queue.
  • Topic: Messages are routed to queues based on wildcard matches between the routing key and the routing pattern specified in the binding.
  • Fanout: It routes messages to all of the queues bound to it, ignoring the routing key.
  • Headers: Routes based on header values instead of the routing key. It's similar to topic but uses message header attributes for routing.