Kafka - How to commit offset after every message using High-Level consumer?

前端 未结 2 653
傲寒
傲寒 2020-12-13 04:41

I\'m using Kafka\'s high-level consumer. Because I\'m using Kafka as a \'queue of transactions\' for my application, I need to make absolutely sure I don\'t miss or re-read

相关标签:
2条回答
  • 2020-12-13 05:09

    There are two relevant settings from http://kafka.apache.org/documentation.html#consumerconfigs.

    auto.commit.enable
    

    and

    auto.commit.interval.ms
    

    If you want to set it such that the consumer commits the offset after each message, that will be difficult since the only setting is after a timer interval, not after each message. You will have to do some rate prediction of the incoming messages and accordingly set the time.

    In general, it is not recommended to keep this interval too small because it vastly increases the read/write rates in zookeeper and zookeeper gets slowed down because it's strongly consistent across its quorum.

    0 讨论(0)
  • 2020-12-13 05:18

    You could first disable auto commit: auto.commit.enable=false

    Then commit after fetching the message: consumer.commitOffsets(true)

    0 讨论(0)
提交回复
热议问题