Bird
0
0

What is wrong with this Kafka consumer group code snippet?

medium📝 Debug Q14 of 15
Kafka - Consumer Groups
What is wrong with this Kafka consumer group code snippet?
props.put("group.id", "my-group");
props.put("enable.auto.commit", "false");
consumer.subscribe(Arrays.asList("my-topic"));
consumer.poll(Duration.ofMillis(100));
// Missing commit after poll
AThe poll timeout is too long
BThe group.id is incorrectly set
CThe consumer subscribes to the wrong topic
DThe consumer never commits offsets, risking message reprocessing
Step-by-Step Solution
Solution:
  1. Step 1: Analyze auto commit setting

    Auto commit is disabled, so offsets must be committed manually.
  2. Step 2: Check code for commit call

    Code calls poll but does not commit offsets, so messages may be reprocessed on restart.
  3. Final Answer:

    The consumer never commits offsets, risking message reprocessing -> Option D
  4. Quick Check:

    Auto commit false needs manual commit [OK]
Quick Trick: Disable auto commit means manual commit needed [OK]
Common Mistakes:
  • Forgetting to commit offsets manually
  • Assuming auto commit is enabled by default
  • Ignoring poll timeout relevance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes