How to get data from old offset point in Kafka?

后端 未结 7 2140
别跟我提以往
别跟我提以往 2020-12-12 18:12

I am using zookeeper to get data from kafka. And here I always get data from last offset point. Is there any way to specify the time of offset to get old data?

There

7条回答
  •  余生分开走
    2020-12-12 19:01

    Kafka Protocol Doc is a great source to play with request/response/Offsets/Messages: https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol you use Simple Consumer example as where following code demonstrate the state:

    FetchRequest req = new FetchRequestBuilder()
    
            .clientId(clientName)
    
            .addFetch(a_topic, a_partition, readOffset, 100000) 
    
            .build();
    
    FetchResponse fetchResponse = simpleConsumer.fetch(req);
    

    set readOffset to start initial offset from. but you need to check the max offset as well as above will provide limited offsets count as per FetchSize in last param of addFetch method.

提交回复
热议问题