RabbitMQ

Exchange Types

Pick the exchange type that matches your routing pattern: direct, topic, fanout, or headers.

The exchange type determines how a message is routed from the exchange to queues. There are four. A direct exchange routes to queues whose binding key exactly matches the message's routing key — ideal for point-to-point or simple level-based routing. A topic exchange matches routing keys against patterns with wildcards (* for one word, # for zero or more), giving flexible publish/subscribe by category.

Direct is addressing a letter to one named department. Topic is a magazine subscription by category ("all sports.football news"). Fanout is the building-wide PA system — everyone hears it. Headers is routing mail by a checklist of attributes (urgent + international) rather than the address line.

Key Concepts

1
A fanout exchange ignores the routing key entirely and broadcasts to every bound queue — the classic pub/sub broadcast. A headers exchange routes on message header attributes instead of the routing key, matching all or any of a set of header values, useful when routing depends on multiple criteria.
2
There is also a default (nameless) exchange: publishing to it with a routing key equal to a queue name delivers straight to that queue, which is why simple examples appear to "publish to a queue".