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
}
Share:
12,249
Manisha
Author by

Manisha

Updated on June 04, 2022

Comments

  • Manisha
    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
    jnodorp about 5 years
  • Gary Russell
    Gary Russell about 5 years
    Thanks; link fixed.
  • Gary Russell
    Gary Russell over 4 years
    Don'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
    S Khandelwal over 3 years
    Can concurrency be changed every time this method get called?
  • Vinit Jordan
    Vinit Jordan over 3 years
    S Khandelwal it will increase till the concurrent number you have added. It will not consume requests more then given concurrency.