Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing messages in RabbitMQ topic exchange that do NOT match a pattern

Two queues are bound to a topic exchange with the following routing keys:

Queue A, bound with routing key pattern match *.foo
Queue B, bound with routing key pattern match *.bar

I'd like to add a third queue to this exchange that receives messages that are neither foo messages nor bar messages. If I bind this queue with a # routing key, I naturally get all messages I need, but including foo's and bar's which I don't want.

Any way to route messages patching a pattern NOT *.foo AND NOT *.bar ?

like image 261
changingrainbows Avatar asked Feb 05 '15 18:02

changingrainbows


People also ask

When special characters and aren't used in bindings The topic exchange will behave just like a?

When special characters "*" (star) and "#" (hash) aren't used in bindings, the topic exchange will behave just like a direct one.

IS routing key required in RabbitMQ?

In this type of exchange, messages are sent to queues based on the routing key. This means that messages sent to a topic exchange must have a specific routing key that must be a list of words, delimited by dots (example, 'acs. deviceoperations.

How will you categorize the different message modes in AMQP?

AMQP allows for various guaranteed messaging modes specifying a message be sent: At-most-once(sent one time with the possibility of being missed). At-least-once (guaranteeing delivery with the possibility of duplicated messages). Exactly-once (guaranteeing a one-time only delivery).

What is exchange and routing key in RabbitMQ?

A direct exchange delivers messages to queues based on a message routing key. The routing key is a message attribute added to the message header by the producer. Think of the routing key as an "address" that the exchange is using to decide how to route the message.


1 Answers

If you want to catch all messages that doesn't match any bindings, that can be done with Alternate Exchange.

Add alternate exchange for existent one and collect all messages from that alternate exchanges:

standard workflow --> [main exchange (topic)]
                    |     --> via binding *.foo -->  [foo queue]
                    |     --> via binding *.bar -->  [bar queue]
                    v      
           [alternate exchange (let it be topic too)]
                    --> via binding * --> []

For more specific cases when you have N bindings but you want to catch all messages that doesn't match M bindings (where M < N) it is more problematic, but technically can be done via Dead Letter Exchange and then publish it to custom exchange where you have only M bindings, and then apply case with Alternate Exchange. But it even sounds rusty, not even think about performance degradation (applied only if you have really high messages flow).

like image 196
pinepain Avatar answered Nov 15 '22 10:11

pinepain