Alternate Exchange in RabbitMQ

So first thing you might be thinking is that What is Alternate Exchange in RabbitMQ ?

The alternate exchange is used to route messages to that exchange in case the message can not be routed because there are no bindings matching the message routing key. This can happen if there is wrong routing key.

If this happens then we might lose the message as it is NOT being routed correctly.

So here comes the alternate exchange and binding a queue to it, then you can get those messages that can't be routed into a queue and consume them.

How to Define an Alternate Exchange ?

For any given exchange, an AE can be defined by clients using policies or the exchange's client-provided options arguments ("x-args").

How Alternate Exchanges Work ?

Whenever an exchange with a configured AE cannot route a message to any queue, it publishes the message to the specified AE instead.

If that AE does not exist then a warning is logged. If an AE cannot route a message, it in turn publishes the message to its AE, if it has one configured. This process continues until either the message is successfully routed, the end of the chain of AEs is reached, or an AE is encountered which has already attempted to route the message.

If you want to learn more about RabbitMQ and its practical implementation with Java, Spring Boot and Spring MVC then just CLICK HERE