[Question] Multiple handlers for a queue separated by routing key
See original GitHub issueHey,
Is it possible to do something like following with golevelup/rabbitmq within the same module?
@RabbitSubscribe({exchange:"any", queue:"user", routingKey:"key1"})
handleKey1() {
...
}
@RabbitSubscribe({exchange:"any", queue:"user", routingKey:"key2"})
handleKey2() {
...
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Part 4: RabbitMQ Exchanges, routing keys and bindings
Topic Exchange: Messages are routed to one or many queues based on a match between a message routing key and the routing pattern....
Read more >AxonAMQP: How to route events to specific queues.
In AMQP, you don't publish to queues, but to Exchanges. Based on the routing key of a message (Axon defaults that to the...
Read more >rabbitmq exchange routing key matching unexpectedly
The routing key on the message is: "FROMDEVICE.MESSAGETYPE:1" and the binding key on the subscription is "#.FROMDEVICE.#". My problem is that ...
Read more >Error Handling with Spring AMQP - Baeldung
It's only aware of exchanges and all produced messages are routed according to the exchange configuration and the message routing key. Now let's ......
Read more >AMQP (RabbitMQ) Support - Spring
RabbitMQ Stream Queue Outbound Channel Adapter ... routingKey("queue1")) // default exchange - route to queue 'queue1' .get(); }.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@eduscrakozabrus You have two handlers which are both bound to the same queue. This is an anti pattern. When you do this, all messages from both routing keys all end up in the same queue, but two handlers are connected to that queue so it is not deterministic which handler will receive the message.
The only way to safely re-use the same queue is if you add conditional logic inside the handler to check the contents of the message but that defeats the purpose of the entire library.
Just don’t re-use queues like this and you won’t have problems
Queues in RabbitMQ are lightweight and they are intended to be purpose driven. There is no benefit to to reusing the same queue for multiple handlers. A typical application that’s properly leveraging RabbitMQ would have dozens if not hundreds or more queues.
A single RabbitMQ node could potentially handle tens of thousands of queues, see for example https://stackoverflow.com/a/22990200/1364771
If you really feel the need to do this (I’d be curious about your reasoning) you could have a single handler that receives all your messages through one queue. The handler could then do conditional processing based on the contents of the message itself.
There are no plans to try and implement the suggested functionality you’ve shown in your original comment as its generally an anti-pattern