Reading messages for specific timestamp in kafka

匆匆过客 提交于 2021-02-10 14:32:48

问题


I want to read all the messages starting from a specific time in kafka. Say I want to read all messages between 0600 to 0800

Request messages between two timestamps from Kafka suggests the solution as the usage of offsetsForTimes.

Problem with that solution is : If say my consumer is switched on everyday at 1300. The consumer would not have read any messages that day, which effectively means no offset was committed at/after 0600, which means offsetsForTimes(< partitionname > , <0600 for that day in millis>) will return null.

Is there any way I can read a message which was published to kafka queue at a certain time, irrespective of offsets?


回答1:


offsetsForTimes() returns offsets of messages that were produced for the requested time. It works regardless if offsets were committed or not because the offsets are directly fetched from the partition logs.

So yes you should be using this method to find the first offset produced after 0600, seek to that position and consume messages until you reach 0800.



来源:https://stackoverflow.com/questions/55095004/reading-messages-for-specific-timestamp-in-kafka

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