Hi,
You don't have to do anything in your application's code - just configure the alternate exchange through a policy as recommended:
For example:
# declare a new exchange
$ rabbitmqadmin declare exchange name=foo type=direct
exchange declared
# publish a message - it can't be routed (no queues bound to the exchange)
$ rabbitmqadmin publish exchange=foo payload="ping" routing_key=1234
Message published but NOT routed
# declare a new queue
$ rabbitmqadmin declare queue name=baz
queue declared
# bind the new queue to amq.fanout (one of the predefined exchanges)
$ rabbitmqadmin declare binding source=amq.fanout destination=baz
binding declared
# declare an alternate exchange for our exchange - when a message can't be routed, it goes to amq.fanout
$ rabbitmqadmin declare policy name=alter pattern='^foo$' definition='{"alternate-exchange":"amq.fanout"}'
policy declared
# publish the message again. - now it is published successfully
$ rabbitmqadmin publish exchange=foo payload="ping" routing_key=1234
Message published
# we can retrieve it from queue "baz"
$ rabbitmqadmin get queue=baz
+-------------+----------+---------------+---------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count | payload | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+---------+---------------+------------------+------------+-------------+
| 1234 | foo | 0 | ping | 4 | string | | False |
+-------------+----------+---------------+---------+---------------+------------------+------------+-------------+