What are the different types of exchanges in RabbitMQ?

Beginner

Answer

Four main exchange types:

  1. Direct Exchange: Routes messages based on exact routing key match
    • Message routing key must exactly match queue binding key
    • Used for unicast routing
  2. Fanout Exchange: Routes messages to all bound queues, ignoring routing key
    • Broadcasts messages to all queues
    • Used for publish/subscribe patterns
  3. Topic Exchange: Routes messages based on wildcard patterns in routing keys
    • Uses patterns with * (one word) and # (zero or more words)
    • Example: stock.*.price matches stock.usd.price
  4. Headers Exchange: Routes based on message headers instead of routing key
    • Matches header attributes using "all" or "any" logic