0

I want to poll only the records that have produced less than 30 seconds. Is there any way in the Kafka polling that I can consume only the messages that are produced only less than 30 seconds?

Any suggestions or advice will be really helpful. Thanks in advance.

aminography
  • 21,986
  • 13
  • 70
  • 74
Manoj
  • 1,833
  • 3
  • 14
  • 11

1 Answers1

2

You could use the offsetsForTimes method which returns you offset whose timestamp is greater or equal to the give timestamp. More information on the official doc here :

https://kafka.apache.org/0101/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#offsetsForTimes(java.util.Map)

After getting the offset you can seek using it and starting to read from there.

https://www.programcreek.com/java-api-examples/index.php?api=org.apache.kafka.clients.consumer.OffsetAndTimestamp

Rohit Yadav
  • 2,252
  • 16
  • 18