如何使用 SimpleMessageListenerContainer 禁用 RabbitMQ 预取计数
How to disable RabbitMQ prefetch count with SimpleMessageListenerContainer
RabbitMQ 提供了选择设置预取计数的能力。
使用 spring-amqp 的 SimpleMessageListenerContainer
,我注意到预取计数始终已设置。我不能将预取计数设置为 0,因为 SimpleMessageListenerContainer
将其设置为至少 txSize
,它必须大于零(即使不涉及任何事务)。那么有没有办法禁用预取计数,即使其不受限制?
这里是来自spring-amqp的相关代码:
SimpleMessageListenerContainer.createBlockingQueueConsumer()
这样做:
int actualPrefetchCount = prefetchCount > txSize ? prefetchCount : txSize;
和BlockingQueueConsumer.start()
这样做:
if (!acknowledgeMode.isAutoAck()) {
// Set basicQos before calling basicConsume (otherwise if we are not acking the broker
// will send blocks of 100 messages)
try {
channel.basicQos(prefetchCount);
}
在 Springs BlockingQueueConsumer
中总是调用 basicQos() 背后的原因是什么?没有禁用预取计数的用例吗? (显然自动确认除外)。
The rabbitmq documentation 讨论了使用通道(全局)范围设置预取计数的开销。与根本不设置相比,使用消费者范围设置它是否有任何开销没有明确提及。如果我没记错的话 spring 总是将其设置为消费者范围。它真的没有开销吗?仍然没有选择不设置它似乎很奇怪。
谢谢
由于当前的实现切换到内部队列,由于早期 rabbitmq 客户端的工作方式,如果消费者无法跟上,不设置 qos 将导致 OOM 条件。
事实上,对于 Spring AMQP 的早期版本,自动确认会发生这种情况,因此队列根据预取大小进行限制,以阻止代理在这种情况下发送消息。
在 2.0 中,我们 planning a new container implementation that avoids this queue 因为 rabbit 客户端不再有需要它的问题。那么可以考虑支持qos=0
RabbitMQ 提供了选择设置预取计数的能力。
使用 spring-amqp 的 SimpleMessageListenerContainer
,我注意到预取计数始终已设置。我不能将预取计数设置为 0,因为 SimpleMessageListenerContainer
将其设置为至少 txSize
,它必须大于零(即使不涉及任何事务)。那么有没有办法禁用预取计数,即使其不受限制?
这里是来自spring-amqp的相关代码:
SimpleMessageListenerContainer.createBlockingQueueConsumer()
这样做:
int actualPrefetchCount = prefetchCount > txSize ? prefetchCount : txSize;
和BlockingQueueConsumer.start()
这样做:
if (!acknowledgeMode.isAutoAck()) {
// Set basicQos before calling basicConsume (otherwise if we are not acking the broker
// will send blocks of 100 messages)
try {
channel.basicQos(prefetchCount);
}
在 Springs BlockingQueueConsumer
中总是调用 basicQos() 背后的原因是什么?没有禁用预取计数的用例吗? (显然自动确认除外)。
The rabbitmq documentation 讨论了使用通道(全局)范围设置预取计数的开销。与根本不设置相比,使用消费者范围设置它是否有任何开销没有明确提及。如果我没记错的话 spring 总是将其设置为消费者范围。它真的没有开销吗?仍然没有选择不设置它似乎很奇怪。
谢谢
由于当前的实现切换到内部队列,由于早期 rabbitmq 客户端的工作方式,如果消费者无法跟上,不设置 qos 将导致 OOM 条件。
事实上,对于 Spring AMQP 的早期版本,自动确认会发生这种情况,因此队列根据预取大小进行限制,以阻止代理在这种情况下发送消息。
在 2.0 中,我们 planning a new container implementation that avoids this queue 因为 rabbit 客户端不再有需要它的问题。那么可以考虑支持qos=0