spring rabbit amqp @RabbitListener配置min和max的消费者数量 [英] spring rabbit amqp @RabbitListener configure min and max number of consumers

查看:1900
本文介绍了spring rabbit amqp @RabbitListener配置min和max的消费者数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring amqp rabbit @RabbitListener annotation
from:artifact spring-rabbit-1.7.1.RELEASE
我想知道是否有办法为每个队列配置多少个消费者?
我一直在挖掘文档并发现什么都没有,有没有办法在相关容器中为每个队列配置多少消费者?
提前致谢。

解决方案

通过容器工厂bean,如文档所示。

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

如果您使用Spring Boot,它会为您创建工厂bean,可以使用属性配置它们。



如果你想要固定数量的消费者,只需省略 max



如果您想为每个监听器设置不同的设置,则每组设置需要不同的工厂。然后,您将在其 containerFactory 属性中为 @RabbitListener 引用特定容器工厂。


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

If you want a fixed number of consumers, just omit the 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.

这篇关于spring rabbit amqp @RabbitListener配置min和max的消费者数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆