Bird
Raised Fist0

What is wrong with this code?

medium📝 Debug Q7 of Q15
Kafka - with Java/Python
What is wrong with this code?
from confluent_kafka import Producer

p = Producer({'bootstrap.servers': 'localhost:9092'})
p.produce('topic', key=123, value='data')
p.flush()
Aflush() must be called before produce()
BValue cannot be a string
Cbootstrap.servers cannot be localhost
DKey must be a bytes or string, not integer
Step-by-Step Solution
Solution:
  1. Step 1: Check key type requirement

    The key argument must be a string or bytes, not an integer.
  2. Step 2: Validate other parts

    Value as string is allowed; flush() order is correct; localhost is valid for testing.
  3. Final Answer:

    Key must be a bytes or string, not integer -> Option D
  4. Quick Check:

    Key type must be string/bytes [OK]
Quick Trick: Keys and values must be string or bytes [OK]
Common Mistakes:
MISTAKES
  • Passing integer as key
  • Misordering flush() call
  • Thinking localhost is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes