I need to consume specific offset to specific end offset!! consumer.seek() reads the data from specific offset but I need retrieve the data fromoffset to tooffset !! Any help will be appreciate , thanks in advance.
ConsumerRecords<String, String> records = consumer.poll(100);
if(flag) {
consumer.seek(new TopicPartition("topic-1", 0), 90);
flag = false;
}
To read messages from a start offset to an end offset, you first need to use
seek()
to move the consumer at the desired starting location and thenpoll()
until you hit the desired end offset.For example, to consume from offset 100 to 200: