RabbitMQ: Alternate Exchange

Alternate Exchange is used to catch “unrouted” message.

  1. Create an exchange called dlx with the type fanout. We choose fanout to catch any routing keys.
  2. Create a queue called dlq and bind it with dlx.
  3. Create an exchange called foo and set it’s alternate_exchange = dlx.
  4. Send message to foo. Since foo is not bound with any queue, by default, the message is lost. But since we set the alternate_exchange in step 3, the message is sent to dlx which after that redirected to dlq.
channel.assertExchange('foo', 'fanout', {
  alternateExchange: 'dlx'
})

References:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *