Dynamic addition of queues to a rabbit listener at runtime

前端 未结 1 1194
孤城傲影
孤城傲影 2020-12-20 14:38

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.

1条回答
  •  Happy的楠姐
    2020-12-20 15:07

    • 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.

    0 讨论(0)
提交回复
热议问题