chandan prakash
chandan prakash

Reputation: 11

Is there any way to set rabbitmq prefetch count to 100000 using spring amqp library?

I am trying to set the prefetch count of 100000 in rabbitmq config, but it sets 34464 as prefetch count for channel.

@Bean
public SimpleRabbitListenerContainerFactory reconFactory(ConnectionFactory connectionFactory,
        SimpleRabbitListenerContainerFactoryConfigurer configurer) {
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    factory.setMessageConverter(jsonMessageConverter());
    factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
    factory.setPrefetchCount(100000);
    factory.setErrorHandler(errorHandler());
    return factory;
}

Expecting the prefecth count to be set to 100000.

Upvotes: 0

Views: 592

Answers (2)

drobert
drobert

Reputation: 1310

This took me forever to track down as I had the same problem recently. The short answer (pun intended; stay tuned) is: no.

The AMQP 0.9.1 Reference specifies prefetch count as type short, which is clarified to be a 16-bit Integer.

It seems like an oversight in the java AMQP client library that it accepts an int when really it should only accept short.

You're getting 16960 because this is the result of truncated the most significant 16 bits of the corresponding 32 bit integer.

The short version is, you can set any prefetch value up to about ~32k (16-bit, 2's-compliment). But 100,000 is not possible.

I would also suggest a bug be filed with the AMQP java client library project as allowing an int to be set is very misleading.

--

Update I've opened a ticket with the rabbitmq amqp library about int vs short here: https://github.com/rabbitmq/rabbitmq-java-client/issues/640

Upvotes: 1

Gary Russell
Gary Russell

Reputation: 174574

Spring (and the amqp-client it uses) sends the 1000000 to the broker.

On my broker, it gets reduced to 16960 so it appears to be a broker property.

You should ask questions about RabbitMQ itself on the rabbitmq-users Google group, where the RabbitMQ engineers hang out. They don't monitor stack overflow closely.

If you get an answer there, you might want to add it here.

Upvotes: 0

Related Questions