Magui87
Magui87

Reputation: 173

How to set offset in kafkalistener

I'm trying to consume data from kafka server, I'm using @Kafkalistener annotation.

The problem is that I'm getting all the messages every time I restart my application. How do I save the last consumed offset in my application and use it to consume next messages?

Upvotes: 6

Views: 5265

Answers (1)

Sourav Gulati
Sourav Gulati

Reputation: 1359

This tutorial has the answer: https://www.codenotfound.com/spring-kafka-boot-example.html

The kafka.consumer.auto-offset-reset property needs to be set to 'earliest' which ensures the new consumer group will get the message sent in case the container started after the send was completed.

So you should set it to latest as per your requirement

Upvotes: 3

Related Questions