Camel RabbitMQ component允许同时设置选项 concurrentConsumers 和 threadPoolSize。它们的描述和默认值如下:
concurrentConsumers- default 1 - Number of concurrent consumers when consuming from broker. (eg similar as to the same option for the JMS component).
threadPoolSize- default 10 - The consumer uses a Thread Pool Executor with a fixed number of threads. This setting allows you to set that number of threads.
有人可以解释这两者将如何相互作用,尤其是从性能的角度来看吗?
特别是,有点细微差别:
threadPoolSize 中指定的一样多,或者这些线程是否在所有并发消费者之间共享?非常感谢!
最佳答案
我在我的机器上做了一些测试,这就是我得到的结果(我没有查看文档,所以我可能是错的):
1. 我注意到消费者的数量是您将附加到队列的“监听器”的数量(他们可以接收消息但将处理委托(delegate)给工作线程)。线程数是实际处理消息的工作线程数。
测试 1: 使用 1 个线程、10 个消费者和 10 条消息,您将同时“传送”(但未确认)10 条消息,其中 1 条消息由单个工作线程一次处理。
测试 2: 有 10 个线程、1 个消费者和 10 条消息,您也将同时处理 1 条消息,但是在处理一条消息时,其他消息在队列中可用(一次仅传递 1 条),因此如果另一个监听器附加,它将能够处理剩余的消息(不是第一个示例中的情况)。
2. 我认为线程是共享的,因为如果不是这种情况,在测试 1 中,10 条消息将被并行使用(每个消费者 1 个线程,总计 10 个线程,而不是只有一个),但事实并非如此。
希望对您有所帮助!
关于java - Camel RabbitMQ 消费者 : what's the interaction between concurrentConsumers and threadPoolSize options?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35334886/