Bird
0
0

Which of the following is the correct way to subscribe a Kafka consumer to multiple topics named "topicA" and "topicB"?

easy📝 Syntax Q12 of 15
Kafka - Consumers
Which of the following is the correct way to subscribe a Kafka consumer to multiple topics named "topicA" and "topicB"?
Aconsumer.subscribe(["topicA", "topicB"])
Bconsumer.subscribe("topicA", "topicB")
Cconsumer.subscribe("topicA" + "," + "topicB")
Dconsumer.subscribe({"topicA", "topicB"})
Step-by-Step Solution
Solution:
  1. Step 1: Recall the subscribe() method signature

    In Kafka, subscribe() takes a list (or collection) of topic names as an argument.
  2. Step 2: Identify correct syntax for multiple topics

    Passing a list like ["topicA", "topicB"] is the correct way to subscribe to multiple topics.
  3. Final Answer:

    consumer.subscribe(["topicA", "topicB"]) -> Option A
  4. Quick Check:

    subscribe() needs a list for multiple topics [OK]
Quick Trick: Use a list to subscribe to multiple topics [OK]
Common Mistakes:
  • Passing multiple string arguments instead of a list
  • Concatenating topic names into one string
  • Using curly braces instead of square brackets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes