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.
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).
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.
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 "*" (star) and "#" (hash) aren't used in bindings, the topic exchange will behave just like a direct one.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With