問題描述
我正在使用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 配置最小和最大消費者數量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!