如何为此队列使用者设置prefetchCount
?
@Bean
public Queue eventQueue(AmqpAdmin amqpAdmin) {
Queue queue = QueueBuilder.durable(EVENT_QUEUE_NAME)
...
.build();
TopicExchange topicExchange = new TopicExchange(TOPIC_EXCHANGE, true, false);
amqpAdmin.declareBinding(BindingBuilder
.bind(queue)
.to(topicExchange)
.with(EVENT_ROUTING_KEY));
return queue;
}
documentation注意,prefetchCount
这是一个容器配置,但是在我的工厂bean上设置它无效,并且该值默认为250
:
@Bean
public SimpleRabbitListenerContainerFactory containerFactory(ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setPrefetchCount(10); // doesn't work; defaults to 250
return factory;
}
Prefetch不是队列属性,它是使用者属性。
您的听众是什么样的?
您为容器工厂使用了非标准名称。
[您需要在containerFactory
中添加@RabbitListener
属性,或者需要将bean重命名为rabbitListenerContainerFactory
(覆盖Boot的定义工厂@Bean
)。
您还可以只在application.properties/yaml文件中设置预取(如果使用的是Spring Boot)。