Search code examples
routesrabbitmqamqp

Excluding one route from a *-binding on a RabbitMQ topic exchange


Given a RabbitMQ topic exchange, e.g. x1 with a consumer queue bound like this:

"source": "x1",
"vhost": "rabbit",
"destination": "queue1",
"destination_type": "queue",
"routing_key": "A.*",
"arguments": {}

I now want to route some messages matching A.* to a different queue. For example, A.a should go to queue2 while all other A.* should still land on queue1. The bindings for queue2 will look like this:

"source": "x1",
"vhost": "rabbit",
"destination": "queue2",
"destination_type": "queue",
"routing_key": "A.a",
"arguments": {}

How should the bindings for queue1 look like to exclude A.a but keep the rest? Is it at all possible?


Solution

  • It is not what topic do, so if you have to use this type of exchange, you can't exclude one route from binding.

    You may find rtopic exchange useful:

    The idea is to be able to specify routing patterns when publishing messages. With the default topic exchange patterns are only accepted when binding queues to exchanges.