RabbitMQ - Wildcard in the routing key and binding key

I use rabbitmq to send messages from one server to multiple clients. I want to send a message to all clients, so I created an exchange to which they are all attached. This works great. However, if I want to send a message to several of these clients based on a wildcard in the routing key (and not in the binding key). For example, I say red clients, blue clients and green clients. Sometimes I want all clients to receive a message, sometimes I only need blue, or only blue and red. This is a simplified example. To extend this to my real system, imagine that I have hundreds of β€œcolor” differences. I cannot figure out how to do this, since character-characters apparently exist only in key bindings and not in routing keys.

Any advice is appreciated.

+7
rabbitmq routing
source share
1 answer

I think you are trying to do too much with one queue. Given that you know in advance whether the message will be transmitted to all clients or only to one, you must configure two exchanges. One of them is a topic or a direct one when clients will receive messages specially designed for them, like fan exchanges, which will be distributed to another set of queues that will be read by all clients. Sharing headers can allow you the flexibility you want, and another option is to write a custom exchange to do exactly what you need.

+18
source share

All Articles