Bird
Raised Fist0

Given this code, what will be printed?

medium📝 Predict Output Q5 of Q15
Kafka - with Java/Python
Given this code, what will be printed?
from confluent_kafka import Producer

def delivery_report(err, msg):
    if err is not None:
        print(f"Message failed: {err}")
    else:
        print(f"Message delivered to {msg.topic()} [{msg.partition()}]")

p = Producer({'bootstrap.servers': 'localhost:9092'})
p.produce('my-topic', value='hello', callback=delivery_report)
p.flush()
AMessage delivered to my-topic [partition_number]
BMessage failed: error_message
CNo output because callback is ignored
DSyntax error due to missing key argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand delivery_report callback

    The callback prints success or failure message after delivery.
  2. Step 2: Since no error, success message prints

    Assuming no error, it prints "Message delivered to my-topic [partition_number]".
  3. Final Answer:

    Message delivered to my-topic [partition_number] -> Option A
  4. Quick Check:

    Callback prints delivery success message [OK]
Quick Trick: Use callback to confirm message delivery [OK]
Common Mistakes:
MISTAKES
  • Assuming callback is ignored
  • Expecting error without cause
  • Missing flush() causing no callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes