Bird
0
0

Find the bug in this Kafka consumer code:

medium📝 Debug Q7 of 15
Kafka - Event-Driven Architecture
Find the bug in this Kafka consumer code:
consumer.subscribe(List.of("topic"));
ConsumerRecords records = consumer.poll(100);
for (ConsumerRecord record : records) {
  System.out.println(record.value());
}
ANo bug, code is correct
Bsubscribe() needs a Set, not a List
CConsumerRecord cannot be used in for-each loop
Dpoll() requires a Duration, not an int
Step-by-Step Solution
Solution:
  1. Step 1: Check poll() method parameter type

    In modern Kafka clients, poll() expects a Duration object, not an int.
  2. Step 2: Confirm correct usage

    Use poll(Duration.ofMillis(100)) instead of poll(100).
  3. Final Answer:

    poll() requires a Duration, not an int -> Option D
  4. Quick Check:

    poll() needs Duration parameter [OK]
Quick Trick: Use Duration.ofMillis() for poll timeout [OK]
Common Mistakes:
  • Passing int instead of Duration to poll()
  • Confusing List and Set for subscribe()
  • Misusing ConsumerRecord in loops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes