简体   繁体   English

Spring boot AMQP并发侦听器按顺序执行?

[英]Spring boot AMQP Concurrent listeners execute sequentially?

I have a Spring AMQP listener defined like this :-我有一个这样定义的 Spring AMQP 侦听器:-

@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.现在在 rabbitmq 管理门户中,当上述服务关闭时,我将发布 30 条消息,并启动侦听器服务。

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.当我这样做时,尽管我将并发性设置为 10,但如上面的代码段所示,消息是按顺序(一个接一个)而不是并行(一次 10 个)执行的。

Any reason why this is happening and any fix for this?发生这种情况的任何原因以及对此有何解决方法?

I believe you are affected by the prefetchCount - by default it's 250 so all the messages are going to one consumer.我相信您会受到prefetchCount影响 - 默认情况下它是 250,因此所有消息都将发送给一个消费者。

Reduce it to distribute across the consumers but I recommend keeping it higher than 1;减少它以分布在消费者中,但我建议将其保持在 1 以上; otherwise it will hurt performance.否则会影响性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM