Bird
0
0

Given this Kafka consumer code snippet:

medium📝 Predict Output Q4 of 15
Kafka - Event-Driven Architecture
Given this Kafka consumer code snippet:
consumer.subscribe(List.of("orders"));
ConsumerRecords records = consumer.poll(Duration.ofMillis(100));
for (var record : records) {
  System.out.println(record.value());
}

What will be the output if the topic 'orders' has messages "order1", "order2"?
ANo output because poll timeout is too short
Border1\norder2
COnly order1 is printed
DCompilation error due to var usage
Step-by-Step Solution
Solution:
  1. Step 1: Understand consumer subscription and polling

    The consumer subscribes to 'orders' and polls messages with a 100ms timeout.
  2. Step 2: Check the for-loop output

    All messages received in poll are printed line by line, so both "order1" and "order2" print.
  3. Final Answer:

    order1\norder2 -> Option B
  4. Quick Check:

    Polling returns all messages available [OK]
Quick Trick: poll() returns all available messages within timeout [OK]
Common Mistakes:
MISTAKES
  • Assuming poll timeout prevents message retrieval
  • Thinking var causes compile error in Java 17+
  • Expecting only one message printed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes