How to read data using Kafka Consumer API from beginning?

前端 未结 10 2057
清歌不尽
清歌不尽 2020-12-05 02:06

Please can anyone tell me how to read messages using the Kafka Consumer API from the beginning every time when I run the consumer.

10条回答
  •  孤街浪徒
    2020-12-05 02:23

    If you are using the java consumer api more specifically org.apache.kafka.clients.consumer.Consumer, You can try the seek* methods.

    consumer.seekToBeginning(consumer.assignment())
    

    Here, consumer.assignment() returns all the partitions assigned to a given consumer and seekToBeginning will start from the earliest offset for the given collection of partitions.

提交回复
热议问题