简体   繁体   English

Spring Rabbit Amqp @RabbitListener配置最小和最大消费者数

[英]spring rabbit amqp @RabbitListener configure min and max number of consumers

I am using spring amqp rabbit @RabbitListener annotation from : artifact spring-rabbit-1.7.1.RELEASE I wonder if there is a way to configure for each queue the number of consumers ? 我正在使用spring amqp Rabbit @RabbitListener批注,其注释来自:artifact spring-rabbit-1.7.1.RELEASE我想知道是否有一种方法可以为每个队列配置使用者数量? I have been digging in the documentation and found nothing yet , is there a way to configure in the related container for each queue the number of consumers ? 我一直在查阅文档,但未发现任何内容,是否可以在相关容器中为每个队列配置使用者数量? Thanks in advance. 提前致谢。

Configure the concurrency via the container factory bean as shown in the documentation . 如文档所示,通过容器工厂bean配置并发。

@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory());
    factory.setConcurrentConsumers(3);
    factory.setMaxConcurrentConsumers(10);
    return factory;
}

If you are using Spring Boot, which creates the factory bean for you, you can configure them using properties. 如果您使用的是Spring Boot,它将为您创建工厂bean,则可以使用属性对其进行配置。

If you want a fixed number of consumers, just omit the max . 如果您想要固定数量的消费者,则只需省略max

If you want different settings for each listener, you need a different factory for each set of settings. 如果要为每个侦听器设置不同的设置,则每个设置的设置都需要一个不同的工厂。 You would then reference the particular container factory for a @RabbitListener in its containerFactory property. 然后,您可以在其containerFactory @RabbitListener属性中为@RabbitListener引用特定的容器工厂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM