Oleg Sklyar
Oleg Sklyar

Reputation: 10082

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?

Upvotes: 2

Views: 2797

Answers (2)

pinepain
pinepain

Reputation: 12859

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.

Upvotes: 2

cantSleepNow
cantSleepNow

Reputation: 10192

AFAIK you can't really make a routing key by saying "not this" or something similar.

To achieve what you want, you could try with a bit of a workaround: to set a big prefetch count to queue 2 consumer and make sure that that consumer is the first to connect to the broker (because of round robin dispatch). You'd have to figure out to what to set the prefetch count to.

Of course, there are many reasons for this not to always work (what if consumers drops, or is too slow etc...)

Upvotes: 0

Related Questions