Bird
Raised Fist0

Which of the following is the correct way to initialize a Kafka producer using a typical SDK?

easy📝 Syntax Q12 of Q15
Kafka - with Java/Python
Which of the following is the correct way to initialize a Kafka producer using a typical SDK?
Aproducer = KafkaProducer('localhost:9092')
Bproducer = KafkaProducer(servers=['localhost:9092'])
Cproducer = KafkaProducer(bootstrap_servers='localhost:9092')
Dproducer = KafkaProducer(connect='localhost:9092')
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kafka SDK producer initialization syntax

    Most Kafka SDKs use the parameter 'bootstrap_servers' to specify Kafka brokers.
  2. Step 2: Match the correct parameter name

    producer = KafkaProducer(bootstrap_servers='localhost:9092') uses 'bootstrap_servers' correctly with the broker address.
  3. Final Answer:

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

    Correct parameter name = producer = KafkaProducer(bootstrap_servers='localhost:9092') [OK]
Quick Trick: Remember 'bootstrap_servers' for Kafka connection [OK]
Common Mistakes:
MISTAKES
  • Using wrong parameter names like 'servers' or 'connect'
  • Passing broker as a plain string without parameter
  • Confusing producer initialization with consumer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes