Search code examples
javaspringspring-amqp

Spring boot AMQP Concurrent listeners execute sequentially?


I have a Spring AMQP listener defined like this :-

@RabbitListener(queues = "spring-boot-durable", concurrency="10")
public void recieve(String message) {
   ....some code here
}

Now in rabbitmq management portal i am publishing 30 messages when the above service is down, and bringing the listener service up.

When i do this, the messages are executed sequentially (one by one) rather than parallelly (10 at a time) although i set the concurrency to 10 as shown in the above piece of code.

Any reason why this is happening and any fix for this?


Solution

  • I believe you are affected by the prefetchCount - by default it's 250 so all the messages are going to one consumer.

    Reduce it to distribute across the consumers but I recommend keeping it higher than 1; otherwise it will hurt performance.