Bird
0
0

Given this Kafka consumer code snippet using an advanced pattern:

medium📝 Predict Output Q13 of 15
Kafka - Advanced Stream Processing
Given this Kafka consumer code snippet using an advanced pattern:
consumer.subscribe(['orders'])
for message in consumer:
    process(message)
    consumer.commit()

What is the main benefit of calling consumer.commit() after processing each message?
AIt speeds up message consumption drastically
BIt deletes the message from the topic
CIt ensures messages are not lost or processed twice
DIt pauses the consumer until manual restart
Step-by-Step Solution
Solution:
  1. Step 1: Understand commit in Kafka consumer

    Committing offsets marks messages as processed to avoid reprocessing.
  2. Step 2: Effect of commit after processing

    Committing after processing ensures no message is lost or duplicated on restart.
  3. Final Answer:

    It ensures messages are not lost or processed twice -> Option C
  4. Quick Check:

    Commit = Avoid duplicates/loss [OK]
Quick Trick: Commit after processing prevents duplicates [OK]
Common Mistakes:
MISTAKES
  • Thinking commit deletes messages
  • Assuming commit speeds consumption
  • Believing commit pauses consumer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes