Chapter

Exchanges and routing

How RabbitMQ decides where a message goes: the default, direct, fanout, topic and headers exchanges, plus dead-letter routing.

RabbitMQ Basics 6 Lessons from courses

About this chapter

So far every message you published landed in one queue. Real systems need to send the same message to many places, or pick a destination from the message itself. That job belongs to exchanges. This chapter walks through each exchange type, from the nameless default you've already been using to topic patterns and dead-letter routing.

Lessons from courses

  1. 1 The default exchange The RabbitMQ default exchange explained: why a routing key equal to the queue name works, how the nameless direct exchange routes, and where it stops.
  2. 2 Direct exchange Declare a RabbitMQ direct exchange, bind a queue with a routing key and publish by exact match in php-amqplib. Route log messages by severity like error.
  3. 3 Fanout exchange A RabbitMQ fanout exchange ignores the routing key and broadcasts every message to all bound queues. Build pub/sub in php-amqplib with a queue per consumer.
  4. 4 Topic exchange Route by dotted routing keys with a RabbitMQ topic exchange in php-amqplib. Use the * and # wildcards to subscribe to patterns like order.created.eu.
  5. 5 Headers exchange Route by message headers instead of a routing key with a RabbitMQ headers exchange in php-amqplib. Understand x-match all vs any and when to use it.
  6. 6 Dead-letter exchanges Configure a RabbitMQ dead-letter exchange via x-dead-letter-exchange in php-amqplib so rejected, expired or overflowing messages get routed instead of vanishing.
RabbitMQ Basics Go to course