You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Yuri da Costa Gouveia <yu...@eng.ci.ufpb.br> on 2017/07/18 18:39:29 UTC
Get data from old offsets
Hello,
I am having trouble to get the data from old offsets. I'm using the version
0.10.2.1, and I need any assistance to recover this data.
This is my consumer class:
String topicName = "test";
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "test");
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("session.timeout.ms", "30000");
props.put("key.deserializer", StringDeserializer.class.getName());
props.put("value.deserializer", StringDeserializer.class.getName());
Thread.currentThread().setContextClassLoader(null);
KafkaConsumer<String, String> consumer = new KafkaConsumer
<String, String>(props);
//Kafka Consumer subscribes list of topics here.
consumer.subscribe(Arrays.asList(topicName));
//print the topic name
System.out.println("Subscribed to topic " + topicName);
int i = 0;
while (true) {
ConsumerRecords<String, String> records = consumer.poll(100);
for (ConsumerRecord<String, String> record : records)
// print the offset,key and value for the consumer records.
System.out.printf("offset = %d, key = %s, value = %s\n",
record.offset(), record.key(), record.value());
}