Bird
Raised Fist0

Given this Kafka SDK code snippet, what will be the output if the message is sent successfully?

medium📝 Predict Output Q13 of Q15
Kafka - with Java/Python
Given this Kafka SDK code snippet, what will be the output if the message is sent successfully?
producer = KafkaProducer(bootstrap_servers='localhost:9092')
future = producer.send('my_topic', b'hello')
result = future.get(timeout=10)
print(result)
ANone
BTimeoutError
CSyntaxError
DRecordMetadata(topic='my_topic', partition=0, offset=0)
Step-by-Step Solution
Solution:
  1. Step 1: Understand what producer.send returns

    It returns a Future object that resolves to RecordMetadata on success.
  2. Step 2: Calling future.get(timeout=10) waits for send result

    If successful, it returns metadata including topic, partition, and offset.
  3. Final Answer:

    RecordMetadata(topic='my_topic', partition=0, offset=0) -> Option D
  4. Quick Check:

    Send success returns RecordMetadata = RecordMetadata(topic='my_topic', partition=0, offset=0) [OK]
Quick Trick: Send returns metadata object on success [OK]
Common Mistakes:
MISTAKES
  • Expecting None as send returns a Future
  • Confusing timeout error with normal output
  • Thinking syntax error occurs here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes