How do I set the prefetchCount on for this queue consumer?
@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;
}
The documentation notes that prefetchCount this is a container configuration, but setting it on my factory bean did not work and the value defaulted to 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;
}
UPDATE
Per @GaryRussell's comment below, I did test out the default rabbitListenerContainerFactory and also validated my Spring Boot configuration spring.rabbitmq.listener.simple.prefetch was being consumed in AbstractRabbitListenerContainerFactoryConfigurer. However, when I look at the queue consumers in RabbitMQ, I can see that the queues that I define using the default container setup still have a prefetchCount of 250:
I'm using the RabbitMQ admin panel as the source of truth. I don't think it's lying, because I have a bunch of dynamic queues that are instantiated with custom containers, and those do have non-default (correct) prefetchCounts. I also validated in the Spring container startup that there was only the one (expected) rabbitListenerContainerFactory bean.

