spring rabbit amqp @RabbitListener 配置最小和最大消费者数量

我正在使用spring amqp rabbit @RabbitListener 注解来自:神器 spring-rabbit-1.7.1.RELEASE我想知道是否有办法为每个队列配置消费者数量?我一直在挖掘文档,但一无所获,有没有办法在相关容器中为每个队列配置消费者数量?提前致谢.

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.

推荐答案

通过文档中显示的容器工厂bean.

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

如果您使用的是 Spring Boot,它会为您创建工厂 bean,您可以使用属性对其进行配置.

If you are using Spring Boot, which creates the factory bean for you, you can configure them using properties.

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

If you want a fixed number of consumers, just omit the max.

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

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.

相关文章