在 Spring Kafka 上偏移提交,而 setBatchListener(true) 为 enable.auto.commit true
Offset commit on Spring Kafka while setBatchListener(true) with enable.auto.commit true
有人可以帮助理解消费者线程何时会在 spring kafka 批处理侦听器和自动提交设置为 true 的情况下提交偏移量吗?默认情况下,消费者线程会在处理完批处理中的所有消息后提交偏移量吗?我知道 autoCommit 是否为假,提交将基于 AckModes,但想知道 autoCommit 何时为真
- Spring Kafka - batchListener -true
- enable.auto.commit - 真
- MAX_POLL_RECORDS_CONFIG - 默认 (500)
- MAX_POLL_INTERVAL_MS_CONFIG - 默认(5 分钟)
对于 enable.auto.commit=true
,容器完全不负责提交偏移量 - 这完全取决于 kafka-clients 库中的算法。
来自kafka文档:
If true the consumer's offset will be periodically committed in the background.
另见 auto.commit.interval.ms
The frequency in milliseconds that the consumer offsets are auto-committed to Kafka if enable.auto.commit is set to true.
默认情况下设置为 5 秒,因此如果您处理一个批处理的时间少于该时间,则在批处理完成时可能会或可能不会提交偏移量。客户端在下一次轮询开始时检查自上次提交以来的时间。
我更喜欢将它设置为 false
这样你就有了 well-defined 的行为——容器将在批处理监听器正常退出时提交偏移量。
有人可以帮助理解消费者线程何时会在 spring kafka 批处理侦听器和自动提交设置为 true 的情况下提交偏移量吗?默认情况下,消费者线程会在处理完批处理中的所有消息后提交偏移量吗?我知道 autoCommit 是否为假,提交将基于 AckModes,但想知道 autoCommit 何时为真
- Spring Kafka - batchListener -true
- enable.auto.commit - 真
- MAX_POLL_RECORDS_CONFIG - 默认 (500)
- MAX_POLL_INTERVAL_MS_CONFIG - 默认(5 分钟)
对于 enable.auto.commit=true
,容器完全不负责提交偏移量 - 这完全取决于 kafka-clients 库中的算法。
来自kafka文档:
If true the consumer's offset will be periodically committed in the background.
另见 auto.commit.interval.ms
The frequency in milliseconds that the consumer offsets are auto-committed to Kafka if enable.auto.commit is set to true.
默认情况下设置为 5 秒,因此如果您处理一个批处理的时间少于该时间,则在批处理完成时可能会或可能不会提交偏移量。客户端在下一次轮询开始时检查自上次提交以来的时间。
我更喜欢将它设置为 false
这样你就有了 well-defined 的行为——容器将在批处理监听器正常退出时提交偏移量。