Rabbitmq concurrent consumers in Spring boot
12,249
Solution 1
With the default configuration, a new consumer will be added every 10 seconds if the other consumers are still busy.
The algorithm (and properties to affect it) is described here.
Solution 2
You can create max concurrent consumers using rabbitMQ annotation
@RabbitListener(queues = "your-queue-name", concurrency = "4")
public void customCheck(Object requestObject) {
// process
}
Author by
Manisha
Updated on June 04, 2022Comments
-
Manisha almost 2 years
I'm using @RabbitListener annotation and SimpleRabbitListenerContainerFactory bean for parallel execution of rabbitmq messages and setting the min and max concurrent consumers in the following way :
@Bean public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setConnectionFactory(connectionFactory()); factory.setConcurrentConsumers(MIN_RABBIT_CONCURRENT_CONSUMERS); factory.setMaxConcurrentConsumers(MAX_RABBIT_CONCURRENT_CONSUMERS); factory.setConsecutiveActiveTrigger(1); factory.setAcknowledgeMode(AcknowledgeMode.MANUAL); return factory; }
The min limit is 3 and the max limit is 10. With this configuration, only 3 messages are getting executed parallelly, even though there are 12 messages in the queue.
Please tell me what is wrong with the config?
-
jnodorp about 5 yearsDocumentation moved to docs.spring.io/spring-amqp/reference/#listener-concurrency
-
Gary Russell about 5 yearsThanks; link fixed.
-
Gary Russell over 4 yearsDon't ask new questions on year-old answers. Yes, it comes standard with Spring AMQP. If you need more information, ask a new question.
-
S Khandelwal over 3 yearsCan concurrency be changed every time this method get called?
-
Vinit Jordan over 3 yearsS Khandelwal it will increase till the concurrent number you have added. It will not consume requests more then given concurrency.