The broker never knows what you processed - only what you told it you processed.
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
while (true) {
var records = consumer.poll(Duration.ofMillis(500));
for (var r : records) process(r);
consumer.commitSync(); // after processing
}
Commit BEFORE processing -> at-most-once (crash = message lost)
Commit AFTER processing -> at-least-once (crash = message redelivered)
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11