In Part 2 we saw how we can detect that a message was unroutable, in this part we'll look at how you can deal with that situation.
RabbitMq offers us the Alternative Exchange for this purpose. When we declare an exchange we can specify the name of an alternative exchange that messages will be forwarded to when a message is unroutable. We just need to make sure that we bind a queue to that exchange that accepts all messages.
New code in Github has been added for this Part 3 that creates the necessary exchanges, queues and bindings. Let's run it and see what happens.
Let's send 1 message to the "order" topic exchange with the routing key "modified". The "order" exchange has declared the "order.unroutable" exchange as its alternative exchange. The "order" exchange also has one queue bound to it with the "new" binding, so only messages with the routing key "new" are routable.
So we see that all 10 messages ended up in the order.unroutable queue and all messages were positively acknowledged with an ack.
In the RabbitMq web console we see the same.
Once a message gets to this queue, it is up to you how to deal with it. You might be able to build some kind of automated system that can consume these messages and decide what to do. Or you can build some kind of Web UI that allows a human to triage unroutable messages and take action.