Alternate Exchanges
Overview
It is sometimes desirable to let clients handle messages that an exchange was unable to route (i.e. either because there were no bound queues or no matching bindings). Typical examples of this are
- detecting when clients accidentally or maliciously publish messages that cannot be routed
- "or else" routing semantics where some messages are handled specially and the rest by a generic handler
Alternate Exchange ("AE") is a feature that addresses these use cases.
How to Define an Alternate Exchange
For any given exchange except for the default one, an AE can be defined by clients using policies. This is the recommended option as policies are significantly simplify changes to such options (e.g. during upgrades).
In modern RabbitMQ versions, the default exchange is a special-cased convention in the code and not a "real" exchange. Therefore it does not support the alternate exchange feature.
Alternatively, optional exchange arguments can be provided by client at exchange declaration time. In the case where both policy and arguments specify an AE, the one specified in arguments overrules the one specified in policy.