Request messages between two timestamps from Kafka

陌路散爱 提交于 2019-12-07 04:26:34

问题


Is it possible to consume messages from Kafka based on a time period in which the messages were ingested?

Example: I want all messages ingested to a topic between 0900-1000 today (and now it's 1200).

If there is only a way to specify a start time, that's fine - my consumer can stop processing messages once it reaches the end time.

I can see methods for requesting messages from a given offset, and for getting the first available offset, and for the earliest available offset, but not all messages after a given time.


回答1:


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://stackoverflow.com/questions/44719884/request-messages-between-two-timestamps-from-kafka

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!