I\'ve got a project where we are going to have hundreds (potentially thousands) of queues in rabbit and each of these queues will need to be consumed by a pool of consumers.
Inject (@Autowired
or otherwise) the RabbitListenerEndpointRegistry
.
Get a reference to the listener container (use the id
attribute on the annotation to give it a known id) (registry.getListenerContainer(id)
).
Cast the container to an AbstractMessageListenerContainer
and call addQueues()
or addQueueNames()
.
Note that is more efficient to use a DirectMessageListenerContainer
when adding queues dynamically; with a SimpleMessageListenerContainer
the consumer(s) are stopped and restarted. With the direct container, each queue gets its own consumer(s).
See Choosing a container.