Bird
Raised Fist0

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

easy📝 Syntax Q3 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?

AKafkaConsumer('my_topic', server='localhost')
BKafkaConsumer('my_topic', bootstrap_servers='localhost:9092')
CKafkaConsumer(topic='my_topic', server='localhost:9092')
DKafkaConsumer('my_topic', brokers='localhost:9092')
Step-by-Step Solution
Solution:
  1. Step 1: Check correct parameter names

    The correct parameter for Kafka server is bootstrap_servers.
  2. Step 2: Validate topic argument

    The topic name is passed as the first argument as a string or list.
  3. Final Answer:

    KafkaConsumer('my_topic', bootstrap_servers='localhost:9092') -> Option B
  4. Quick Check:

    bootstrap_servers is correct server param [OK]
Quick Trick: Use bootstrap_servers to set Kafka address [OK]
Common Mistakes:
MISTAKES
  • Using wrong parameter names like server or brokers
  • Passing topic as keyword argument
  • Omitting bootstrap_servers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes