java - kafka消费者自动提交是如何工作的?

标签 java apache-kafka offset kafka-consumer-api autocommit

我正在阅读 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/

相关文章:

java - 将 .txt 解析为 .csv

java - Kafka Stream 真的是实时的吗?

java - Spring Kafka-Consumer.poll() 到底什么时候在幕后被调用?

apache-spark - Spark 结构化流与 kafka 导致只有一个批处理(Pyspark)

python - 如何用数组干净地索引 numpy 数组(或任何其他支持加法的东西,以便它可以被抵消)

java - 以编程方式获取键盘左侧的一个字符

java - 如何从google plus中的圈子中检索帖子

java - 滚动 JScrollPane 时出现问题 - 线程

php - fatal error : Cannot use string offset as an array

limit - SPARQL 中的括号是什么?为什么链接的电影数据库限制为 2500 条记录?