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

Hongyi Li

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 any messages. I have 2 questions regarding this:

  1. How do I commit the offset to zookeeper? I will turn off auto-commit and commit offset after every message successfully consumed. I can't seem to find actual code examples of how to do this using high-level consumer. Can anyone help me with this?

  2. On the other hand, I've heard committing to zookeeper might be slow, so another way may be to locally keep track of the offsets? Is this alternative method advisable? If yes, how would you approach it?

laughing_man

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Kafka Consumer not able to read all message after offset commit (error=OFFSET_OUT_OF_RANGE

分類Dev

Kafka consumer manual commit offset

分類Dev

Kafka Consumer configuration - How does auto.offset.reset controls the message consumption

分類Dev

Who keeps track of the last read message offset of the consumer in Apache Kafka?

分類Dev

How to set offset committed by the consumer group using Spark's Direct Stream for Kafka?

分類Dev

Kafka Stream: Consumer commit frequency

分類Dev

Incorrect Kafka offset across consumer groups

分類Dev

Kafka Streams: How to ensure offset is committed after processing is completed

分類Dev

Kafka Offset after retention period

分類Dev

Kafka consumer does not start from latest message

分類Dev

Spark 1.6 Streaming consumer reading in kafka offset stuck at createDirectStream

分類Dev

Spring kafka Consume multiple Message types in one consumer

分類Dev

Spring kafka Consume multiple Message types in one consumer

分類Dev

Apache Kafka: Can we restrict message to be read by only 1 consumer?

分類Dev

Kafka what will happen with message if a consumer group member goes down?

分類Dev

git: how to obtain the commit message of the file before it gets committed using pre-commit hook?

分類Dev

How do I implement Kafka Consumer in Scala

分類Dev

Offset commit on Spring Kafka while setBatchListener(true) with enable.auto.commit true

分類Dev

Modify commit message on gerrit after patchset creation?

分類Dev

RabbitMQ - How to save message for new consumer

分類Dev

How to get the processing kafka topic name dynamically in Flink Kafka Consumer?

分類Dev

Is consumer offset commited even when failing to post to output topic in Kafka Streams?

分類Dev

Message pre-processing (topic - topic) - Kafka Connect API vs. Streams vs Kafka Consumer?

分類Dev

How to detect if kafka broker is not available from consumer in java?

分類Dev

How to have multiple kafka consumer groups in application properties

分類Dev

How to create Kafka user and consumer group for ACLs in a running cluster?

分類Dev

How to utilize existing avro schema for my kafka consumer?

分類Dev

Kafka MirrorMakerが__consumer_offsetトピックの複製に失敗する

分類Dev

Kafka Consumer with JAVA

Related 関連記事

  1. 1

    Kafka Consumer not able to read all message after offset commit (error=OFFSET_OUT_OF_RANGE

  2. 2

    Kafka consumer manual commit offset

  3. 3

    Kafka Consumer configuration - How does auto.offset.reset controls the message consumption

  4. 4

    Who keeps track of the last read message offset of the consumer in Apache Kafka?

  5. 5

    How to set offset committed by the consumer group using Spark's Direct Stream for Kafka?

  6. 6

    Kafka Stream: Consumer commit frequency

  7. 7

    Incorrect Kafka offset across consumer groups

  8. 8

    Kafka Streams: How to ensure offset is committed after processing is completed

  9. 9

    Kafka Offset after retention period

  10. 10

    Kafka consumer does not start from latest message

  11. 11

    Spark 1.6 Streaming consumer reading in kafka offset stuck at createDirectStream

  12. 12

    Spring kafka Consume multiple Message types in one consumer

  13. 13

    Spring kafka Consume multiple Message types in one consumer

  14. 14

    Apache Kafka: Can we restrict message to be read by only 1 consumer?

  15. 15

    Kafka what will happen with message if a consumer group member goes down?

  16. 16

    git: how to obtain the commit message of the file before it gets committed using pre-commit hook?

  17. 17

    How do I implement Kafka Consumer in Scala

  18. 18

    Offset commit on Spring Kafka while setBatchListener(true) with enable.auto.commit true

  19. 19

    Modify commit message on gerrit after patchset creation?

  20. 20

    RabbitMQ - How to save message for new consumer

  21. 21

    How to get the processing kafka topic name dynamically in Flink Kafka Consumer?

  22. 22

    Is consumer offset commited even when failing to post to output topic in Kafka Streams?

  23. 23

    Message pre-processing (topic - topic) - Kafka Connect API vs. Streams vs Kafka Consumer?

  24. 24

    How to detect if kafka broker is not available from consumer in java?

  25. 25

    How to have multiple kafka consumer groups in application properties

  26. 26

    How to create Kafka user and consumer group for ACLs in a running cluster?

  27. 27

    How to utilize existing avro schema for my kafka consumer?

  28. 28

    Kafka MirrorMakerが__consumer_offsetトピックの複製に失敗する

  29. 29

    Kafka Consumer with JAVA

ホットタグ

アーカイブ