I have a simple java program (dockerized) and deployed in kubernetes (pod) This java program is just a normal java project that listens and consumes to a specific topic. eg. SAMPLE-SAFE-TOPIC
I have to unsubscribe to this topic safely, meaning no data will be lost even I deleted this pod (java consumer).
This is the code that I saw from searching:
public static void unsubscribeSafelyFromKafka() {
logger.debug("Safely unsubscribe to topic..");
if (myKakfaConsumer != null) {
myKafkaConsumer.unsubscribe();
myKafkaConsumer.close();
}
}
I need to run this via command line wherein the Java program has already an existing static main method.
My questions are:
- Is the code above guarantees no records will be lost?
- How can I trigger the code above via command line when there is already an existing static main()
Note: I am running the java project via command line. E.g. java -jar MyKafkaConsumer.jar as this is the requirement.
Please help