posted 1 month ago
Hi,
I am working on coming up with a kafka consumer based on springboot. There is requirement to commit offset within consumer program instead of relying upon auto commit provided by kafka. So when explored on options to do this I found two ways
1. To create ConcurrentMessageListenerContainer within kafka configuration bean by passing acknowledgement mode as AckMode.MANUAL_IMMEDIATE. Pass the reference of class that implements AcknowledgingMessageListener. This will give handle to Acknowledgement object in onMessage method. In onMessage we can consume message then if no exceptions are there we can invoke acknowledge() on Acknowledgement object.
2. To create ConcurrentKafkaListenerContainerFactory within kafka configuration bean by passing acknowledgement mode as AckMode.MANUAL_IMMEDIATE. Then have @KafkaListener annotation with topics and groupid defined. listen method contains handle to Acknowledgement object and once processing of message is completed we can invoke acknowledge() on Acknowledgement object.
Want to understand the pros and cons of above two approaches. To me right now both approaches seems to be achieving same functionality, so if I am implementing kafka consumer, which approach is better to adopt.
Thanks
Kranthi