Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ - Wildcard in routing key vs binding key

I'm using rabbitmq to send messages from a single server to multiple clients. I want to send a message to all clients so I have created an exchange which they all bind to. This works great. However, what if I want to send a message to a handful of these clients based on a wildcard in the routing key (not the binding key). For instance, I have say red clients, blue clients and green clients. Sometimes I want all clients to receive the message, sometimes I want just the blue, or just the blue and the red. This is a simplified example. To extend this to my actual system, imagine I have hundreds of "color" distinctions. I can't figure out how to do this as wildcards seem to only exist in binding keys not routing keys.

Any advice will be greatly appreciated.

like image 292
user3334234 Avatar asked Mar 20 '14 22:03

user3334234


People also ask

What is binding key in RabbitMQ?

A binding is a "link" that you set up to bind a queue to an exchange. The routing key is a message attribute the exchange looks at when deciding how to route the message to queues (depending on exchange type).

Is the routing key act as a filter in binding?

Messages sent with a particular routing key will be delivered to all the queues that are bound with a matching binding key. Filter based routing provides a method to use filter policies on routing key for choosing the recipients of messages. * (star) can substitute for exactly one word. example: 'topic.

What is a RabbitMQ routing key?

The label (routing key) describes the payload and the RabbitMQ messaging system uses this to determine who will receive a copy of your message. Unlike TCP — where you need to specify the sender and receiver — AMQP only describes the message with a label.

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.


1 Answers

I think you are trying to do too much with one queue. Considering that you know ahead of time whether the message will go to all clients or just one then you should set up two exchanges. One as a topic, or direct, where the clients will only get the messages specifically intended for them the other as a fanout exchange that will distribute to a different set of queues that will be read by all clients. Header exchanges may allow you the flexibility you want as well and the other possibility is writing a custom exchange to do exactly what you need.

like image 196
robthewolf Avatar answered Sep 29 '22 19:09

robthewolf