How to make kafka consumer to read from last consumed offset but not from beginning

后端 未结 3 1749
刺人心
刺人心 2021-01-04 10:24

I am new to kafka and trying to understand if there is a way to read messages from last consumed offset, but not from beginning.

I am writing an example case, so tha

3条回答
  •  花落未央
    2021-01-04 10:35

    Setting the auto.offset.reset=earliest, AND a fixed group.id=something in the consumer config will start the consumer at the last committed offset. In your case it should start consuming at the first message at 7:20. If you want it to start reading messages posted AFTER it starts, then the auto.offset.reset=latest will ignore the 10 messages sent at 7:20 and read any that come in after it starts.

    If you want it to start at the beginning, you must either call seekToBeginning after the first consumer.poll(), or change the consumer group ID to something unique.

提交回复
热议问题