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

后端 未结 1 1877
礼貌的吻别
礼貌的吻别 2021-02-11 09:57

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 consum

相关标签:
1条回答
  • 2021-02-11 10:26

    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.

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