Bird
0
0

Which of the following is the correct way to create a Kafka producer in Python using the kafka-python library?

easy📝 Syntax Q12 of 15
Kafka - Basics and Event Streaming
Which of the following is the correct way to create a Kafka producer in Python using the kafka-python library?
Aproducer = KafkaConsumer(topic='mytopic')
Bproducer = KafkaConsumer(bootstrap_servers='localhost:9092')
Cproducer = KafkaProducer(topic='mytopic')
Dproducer = KafkaProducer(bootstrap_servers='localhost:9092')
Step-by-Step Solution
Solution:
  1. Step 1: Identify Kafka producer creation syntax

    KafkaProducer is created with bootstrap_servers parameter specifying Kafka server address.
  2. Step 2: Eliminate consumer and wrong parameters

    KafkaConsumer is for consuming, not producing. Topic is not a parameter for producer creation.
  3. Final Answer:

    producer = KafkaProducer(bootstrap_servers='localhost:9092') -> Option D
  4. Quick Check:

    Producer uses KafkaProducer with bootstrap_servers [OK]
Quick Trick: Producer uses KafkaProducer with bootstrap_servers [OK]
Common Mistakes:
  • Using KafkaConsumer instead of KafkaProducer
  • Passing topic during producer creation
  • Missing bootstrap_servers parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes