简体   繁体   English

RabbitMQ 队列消费行为

[英]RabbitMQ queue consumption behaviour

We have a Spring Boot (2.1) application using Apache Camel (2.24) to consume from a RabbitMQ server (3.7.15).我们有一个 Spring Boot (2.1) 应用程序,它使用 Apache Camel (2.24) 从 RabbitMQ 服务器 (3.7.15) 消费。

The application appears to be consuming correctly (message-by-message, as they are placed on the queue), but in the RabbitMQ monitor it appears as those the messages are consumed 'in bulk' (see the sharp drop then flatline, even though we see in the logs that messages are being processed by the app).应用程序似乎正在正确消费(一条消息,因为它们被放置在队列中),但在 RabbitMQ 监视器中,它显示为那些消息被“批量”消费(参见急剧下降然后平坦,即使我们在日志中看到应用程序正在处理消息)。

We haven't set any sort of 'prefetch' behaviour that I can see.我们没有设置任何我能看到的“预取”行为。 Can someone explain what's happening?有人可以解释发生了什么吗? Why isn't the queue count decreasing smoothly?为什么队列数没有平滑减少?

rabbitmq 管理控制台

Well, it simply looks like the default prefetch value is unlimited .好吧,看起来默认的预取值是无限的 If you want to limit it, you have to explicitly configure it.如果你想限制它,你必须明确地配置它。

I didn't found an official source confirming this impression, but at least an article that does: https://www.cloudamqp.com/blog/2017-12-29-part1-rabbitmq-best-practice.html#prefetch我没有找到证实这种印象的官方来源,但至少有一篇文章确实如此: https : //www.cloudamqp.com/blog/2017-12-29-part1-rabbitmq-best-practice.html#prefetch

RabbitMQ default prefetch setting gives clients an unlimited buffer, meaning that RabbitMQ by default send as many messages as it can to any consumer that looks ready to accept them. RabbitMQ 默认预取设置为客户端提供了一个无限的缓冲区,这意味着 RabbitMQ 默认会向任何看起来准备接受它们的消费者发送尽可能多的消息。

The Camel component has an option prefetchEnabled that is by default false . Camel 组件有一个默认为false的选项prefetchEnabled However, when I look at the RabbitConsumer class of the Camel component in the method openChannel , this just means that the consumer does not explicitly set prefetch values .然而,当我在openChannel方法中openChannel Camel 组件的RabbitConsumer 类时,这只是意味着消费者没有显式设置预取值

A consumer without prefetch settings is not necessarily a consumer with prefetch disabled, it is a consumer that does not care about prefetch (and therefore gets a default that is defined somewhere else ).没有预取设置的消费者不一定是禁用预取的消费者,它是一个不关心预取的消费者(因此获得在其他地方定义的默认值)。

If I have not overlooked something the Camel option prefetchEnabled has not a good name.如果我没有忽略某些东西,Camel 选项prefetchEnabled的名字并不好。 It should be called limitPrefetch .它应该被称为limitPrefetch That would also match with the RabbitMQ docs :这也与RabbitMQ 文档匹配:

... specifies the basic.qos method to make it possible to limit the number of unacknowledged messages on a channel (or connection) ... 指定 basic.qos 方法以限制通道(或连接)上未确认消息的数量

Conclusion: I suspect that if you want a prefetch limit with the Camel component you have to set prefetchEnabled as well as the other prefetch options .结论:我怀疑如果你想要一个Camel 组件的预取限制你必须设置prefetchEnabled以及其他预取选项 Otherwise there is no limit (what basically makes sense since this gives you maximum throughput).否则没有限制(这基本上是有意义的,因为这可以为您提供最大吞吐量)。

from("rabbitmq://localhost:5672/delete.Tenant?queue=tenant&declare=false&autoAck=false&threadPoolSize=20&concurrentConsumers=20&prefetchEnabled=true&prefetchCount=100")

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

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