I am new to kafka and using Apache kafka consumer to read messages from producer. But when I stop and start for certain time. All the produced messages between are lost. how to handle this scenario. I am using these properties "auto.offset.reset", "latest" and "enable.auto.commit", "false" .
This is the code I am using.Any help is appreciated.
Properties props = new Properties();
props.put("bootstrap.servers", localhost:9092);
props.put("group.id", "service");
props.put("enable.auto.commit", "false");
props.put("auto.offset.reset", "latest");
props.put("key.deserializer", KAFKA_DESERIALIER_STRING_KEYVALUE);
props.put("value.deserializer", KAFKA_DESERIALIER_STRING_KEYVALUE);
@SuppressWarnings("resource")
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
consumer.subscribe(Arrays.asList(topicname));
while (true) {
ConsumerRecords<String, String> records = consumer.poll(100);
for (ConsumerRecord<String, String> record : records) {
JSONObject jsonObj = new JSONObject(record.value());
JdbcUtilToUdm.insertdataintodb(args, jsonObj);
}
}