Bird
0
0

What will be the output of this Python code snippet using kafka-python?

medium📝 Predict Output Q4 of 15
Kafka - Basics and Event Streaming
What will be the output of this Python code snippet using kafka-python? from kafka import KafkaProducer producer = KafkaProducer(bootstrap_servers='localhost:9092') future = producer.send('test-topic', b'hello') result = future.get(timeout=10) print(result.topic)
ANone
Bhello
CTimeoutError
Dtest-topic
Step-by-Step Solution
Solution:
  1. Step 1: Understand producer.send and future.get

    producer.send returns a FutureRecordMetadata object; calling get() waits for send confirmation.
  2. Step 2: Access topic attribute from result

    result.topic returns the topic name where the message was sent, which is 'test-topic'.
  3. Final Answer:

    test-topic -> Option D
  4. Quick Check:

    FutureRecordMetadata.topic = 'test-topic' [OK]
Quick Trick: future.get() returns metadata including topic name [OK]
Common Mistakes:
  • Expecting message content as output
  • Ignoring future.get() call
  • Confusing timeout with error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes