我正在阅读 this one :
Automatic Commit The easiest way to commit offsets is to allow the consumer to do it for you. If you configure enable.auto.commit=true, then every five seconds the consumer will commit the largest offset your client received from poll(). The five-second interval is the default and is controlled by setting auto.commit.interval.ms. Just like everything else in the consumer, the automatic commits are driven by the poll loop. Whenever you poll, the consumer checks if it is time to commit, and if it is, it will commit the offsets it returned in the last poll.
可能是我的英语不好,但我没有完全理解这个描述。
假设我使用默认间隔自动提交 - 5 秒,轮询每 7 秒发生一次。在这种情况下,提交将每 5 秒或每 7 秒发生一次?
如果轮询每 3 秒发生一次,您能否阐明行为?提交是每 5 秒还是每 6 秒发生一次?
我读过this one :
Auto commits: You can set auto.commit to true and set the auto.commit.interval.ms property with a value in milliseconds. Once you've enabled this, the Kafka consumer will commit the offset of the last message received in response to its poll() call. The poll() call is issued in the background at the set auto.commit.interval.ms.
它与答案相矛盾。
你能详细解释一下吗?
假设我有这样的图表:
0 sec - poll
4 sec - poll
8 sec - poll
offset 什么时候提交,什么时候提交?
最佳答案
每次轮询都会调用自动提交检查,它会检查耗时是否大于配置的时间。如果是,则提交偏移量。
如果提交间隔为 5 秒并且轮询在 7 秒后发生,则提交只会在 7 秒后发生。
关于java - kafka消费者自动提交是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46546489/