Search code examples
javarabbitmqspring-rabbit

RabbitMQ: How to restrict a routing key format


My producer sends messages to an exchange. I have many consumers and I give each one a different routing key, let's say "a.b.1" to the first, "a.b.2" to the second and so on. I want to prevent any consumer to bind his queue with a routing key matching all messages like "a.b.#". Any idea how to do it ?


Solution

  • As per my understanding you have one exchange and each consumer has his own queue. And you have bound the queues with the exchange with routing keys. example :

    If the routing key is "a.b.1" it will go to q.1 which is consumed by consumer-1.

    If this is the case don't allow consumers to create the queue . That means don't give the consumer CONFIGURE access, so that they can't create queues from their side. You create queues manually in RabbitMQ and configure them to the exchange with the routing key. Also you can put the restriction on the consumer by just giving them READ access over their queue.