I'm trying to seek the offset to some specific offset. It seems I need to use seekToTimestamp and there is no seekToOffset or something. I've research a lot but couldn't find exact implementation of the code. For now I have to consume previous event which is already in topic that's why I've used:
topicPartitions = {@org.springframework.kafka.annotation.TopicPartition(topic = "some_topic",
partitionOffsets = @PartitionOffset(partition = "0", initialOffset = "0"))}
But I have no idea how I can make it. Point listener to specific offset and start from there?
I would be grateful if anyone can help me!
@Component
@Slf4j
@Builder
public class KafkaConsumer extends AbstractConsumerSeekAware {
private final Optional<Long> seekToTimestamp;
@KafkaListener(id = "some_id", topicPartitions = {@org.springframework.kafka.annotation.TopicPartition(topic = "some_topic",
partitionOffsets = @PartitionOffset(partition = "0", initialOffset = "0"))})
public SomeAvroClass listen(SomeAvroClass someAvroClass) throws URISyntaxException, IOException, InterruptedException {
log.info("Consuming event from Kafka" + someAvroClass);
log.info("BEFORE Seek : " + someAvroClass.getCode()));
KafkaConsumer.builder().seekToTimestamp(Optional.of(System.currentTimeMillis()- 6_000_000));
log.info("AFTER Seek : " + someAvroClass.getCode())); //result is same as BEFORE
return someAvroClass;
}
}