我有一个使用案例,其中我们严格要求所有队列都有一个专用线程和消费者,这意味着每个线程只服务一个队列。
我已经阅读了Gary Russell给出的答案和评论。他提到要创建一个子应用程序上下文来拥有@RabbitListener
的所有特性,以实现我正在尝试的功能。但我仍然不知道如何在运行时动态添加队列时做到这一点。
如果可能的话,请给我指一下相关的文章,以解决这个问题,包括应用程序上下文的方式(以及如何创建子上下文)和建议的MessageListenerAdapter
方式。
我有一个使用案例,其中我们严格要求所有队列都有一个专用线程和消费者,这意味着每个线程只服务一个队列。
我已经阅读了Gary Russell给出的答案和评论。他提到要创建一个子应用程序上下文来拥有@RabbitListener
的所有特性,以实现我正在尝试的功能。但我仍然不知道如何在运行时动态添加队列时做到这一点。
如果可能的话,请给我指一下相关的文章,以解决这个问题,包括应用程序上下文的方式(以及如何创建子上下文)和建议的MessageListenerAdapter
方式。
1条答案
按热度按时间z5btuh9x1#
下面是一些基于Spring Boot和子应用程序上下文声明的解决方案。
1.我在组件中有
@RabbitListener
,它将在子上下文中声明:1.我们需要
@EnableRabbit
将各自的注解处理器注册到子应用程序上下文,并能够触发适当的生命周期。AmqpAdmin
,以便能够声明动态队列。1.这两个方面在处理和逻辑上都给了我们一些隔离。
1.下面是我声明这些上下文的方式:
注意
propertySource
要实现一个动态的要求,对于每个子应用程序上下文都有其特定的@RabbitListener
。我的程序的输出是这样的: