Bird
Raised Fist0

Which of the following is the correct way to create a KafkaConsumer in Python to read from topic my_topic on localhost?

easy📝 Syntax Q12 of Q15
Kafka - with Java/Python

Which of the following is the correct way to create a KafkaConsumer in Python to read from topic my_topic on localhost?

from kafka import KafkaConsumer
consumer = KafkaConsumer(_____)
Amy_topic, bootstrap_servers='localhost:9092'
B"my_topic", bootstrap='localhost:9092'
C"my_topic", servers='localhost:9092'
D"my_topic", bootstrap_servers='localhost:9092'
Step-by-Step Solution
Solution:
  1. Step 1: Check KafkaConsumer parameters

    KafkaConsumer expects topic name as string and bootstrap_servers keyword argument.
  2. Step 2: Identify correct syntax

    "my_topic", bootstrap_servers='localhost:9092' uses correct string for topic and correct keyword bootstrap_servers with proper value.
  3. Final Answer:

    "my_topic", bootstrap_servers='localhost:9092' -> Option D
  4. Quick Check:

    Correct syntax uses bootstrap_servers keyword [OK]
Quick Trick: Use bootstrap_servers='host:port' exactly [OK]
Common Mistakes:
MISTAKES
  • Omitting quotes around topic name
  • Using wrong keyword like servers or bootstrap
  • Passing topic name without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes