spring rabbit amqp @RabbitListener configure min and max number of consumers(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.
这篇关于spring rabbit amqp @RabbitListener 配置最小和最大消费者数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:spring rabbit amqp @RabbitListener 配置最小和最大消费者


基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01