Bird
0
0

What is the issue with this Kafka consumer subscription code snippet in Java?

medium📝 Debug Q6 of 15
Kafka - Consumers
What is the issue with this Kafka consumer subscription code snippet in Java?
consumer.subscribe("topic1");
AThe consumer must be closed before subscribing.
BThe topic name "topic1" is invalid.
Csubscribe() cannot be called before consumer.poll().
Dsubscribe() expects a Collection<String>, not a single String argument.
Step-by-Step Solution
Solution:
  1. Step 1: Check subscribe() method signature

    The subscribe() method requires a Collection<String> argument, not a single String.
  2. Step 2: Analyze the code

    Passing a single String causes a compile-time error.
  3. Final Answer:

    subscribe() expects a Collection, not a single String argument. -> Option D
  4. Quick Check:

    subscribe() needs a collection, not a single string. [OK]
Quick Trick: subscribe() requires Collection, not String [OK]
Common Mistakes:
  • Passing a single string instead of a collection
  • Assuming subscribe() can be called with multiple string arguments
  • Ignoring method signature requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes