Bird
0
0

Given this Kafka consumer snippet:

medium📝 Predict Output Q5 of 15
Kafka - Consumers
Given this Kafka consumer snippet:
ConsumerRecords records = consumer.poll(Duration.ofMillis(100));
consumer.commitSync();

What is the effect of calling commitSync() immediately after poll() without processing the records?
AOffsets are not committed because records are not processed
BOffsets are committed for the last polled batch, even if records are unprocessed
CAn exception is thrown due to unprocessed records
DOffsets commit is deferred until records are processed
Step-by-Step Solution
Solution:
  1. Step 1: Understand commitSync behavior

    commitSync() commits the offsets of the last polled records regardless of processing.
  2. Step 2: Effect of calling commitSync immediately

    Calling it immediately after poll() commits offsets even if records are not processed yet.
  3. Final Answer:

    Offsets are committed for the last polled batch, even if records are unprocessed -> Option B
  4. Quick Check:

    commitSync commits last polled offsets regardless of processing [OK]
Quick Trick: commitSync commits offsets of last poll regardless of processing [OK]
Common Mistakes:
  • Assuming commitSync waits for processing before committing
  • Expecting exceptions if records are unprocessed
  • Believing offsets commit is deferred automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes