[rabbitmq-discuss] Binding to topic exchange with a negation wildcard

Simon MacMullen simon at rabbitmq.com
Thu Sep 13 09:40:55 BST 2012

On 12/09/2012 8:37PM, Dave Curylo wrote:
> Is it possible to bind a queue to a topic exchange with a condition that
> the topic does NOT match a certain wildcard?

The topic exchange doesn't have that logic. But you can fake it with the 
alternate exchange feature, at the cost of a few more exchanges.

Declare a fanout exchange you'll publish to (let's call it 
"my-exchange"). Declare a fanout exchange called "junk".

The when each consumer declares a queue, it also declares a topic 
exchange and a fanout exchange. The alternate-exchange for the topic 
exchange should be set to the fanout exchange. It then binds the topic 
exchange to "my-exchange", and "junk" to the topic exchange, with a 
routing key equal to the topics it doesn't want.

Thus messages with the "bad" routing key go:

   [my-exchange] -> [per-consumer-topic] -> [junk]

and the rest go:

   [my-exchange] -> [per-consumer-topic] -> [per-consumer-fanout] -> 

I think that's the simplest you can make it. But exchanges are cheap in 
general, it's just routing logic.

But I wonder whether some sort of more explicit negation feature would 
be feasible / useful. Hmm.

Cheers, Simon

More information about the rabbitmq-discuss mailing list