I have a test automation project. I'm trying to get kafka consumer records starting from the latest record with config ConsumerConfig.AUTO_OFFSET_RESET_CONFIG = "latest"
. But it doesn't work. Here is a code where I'm trying to poll data:
for(int i=0; i<20; i++) {
ConsumerRecords<String, String> consumerRecords = consumer.poll(Duration.ofMillis(500L));
value = findValue(key, consumerRecords);
if(value != null){
break;
}
}
In this code variable consumerRecords
has 0 size in every iteration.
If I change ConsumerConfig.AUTO_OFFSET_RESET_CONFIG
to "earliest"
then consumer.poll()
works and variable consumerRecords
has not 0 size, but elements in collection are starting since earliest offset, while I need elements which are starting since last offset.
How I can achieve consumerRecords
with elements in decreasing order by offset ?
I tried to increase the timeout to polling up to 10 seconds - it didn't help.
kafka-clients:2.7.0