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

本小妞迷上赌 提交于 2019-12-04 14:40:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/43169979/spring-rabbit-amqp-rabbitlistener-configure-min-and-max-number-of-consumers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!