Kafka read topic from beginning


What's inside this article ⌄
  • Kafka new consumer start from beginning
  • Kafka consumer group initial offset
  • Kafka consumer read from start
  • Kafka reset consumer offset

Suppose that you have a Kafka Topic with some data, and you connect to it with Kafka Consumer with a new group.id. But this consumer does not read messages from the beginning of the topic.

Consumer Config has a specific property auto.offset.reset, which indicates which offset will be assigned to the consumer with the new group.id.

The property takes two values:

  • earliest. Then, when connecting to the Consumer topic with a new group.id, it will read the topic from the beginning
  • latest. Then, when connecting to the Consumer topic with a new group.id, it will read the topic from the last fixed Kafka offset.

An example of how to set up a property for a Kafka Consumer:

Properties properties = new Properties();
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");