Bird
Raised Fist0

You want to send multiple messages to Kafka and ensure all are delivered before your program exits. Which sequence of calls is correct using confluent-kafka producer in Python?

hard🚀 Application Q15 of Q15
Kafka - with Java/Python
You want to send multiple messages to Kafka and ensure all are delivered before your program exits. Which sequence of calls is correct using confluent-kafka producer in Python?
ACall <code>produce()</code> for each message, then call <code>flush()</code> once at the end
BCall <code>flush()</code> after each <code>produce()</code> call
CCall <code>flush()</code> before any <code>produce()</code> calls
DCall <code>produce()</code> once, then call <code>flush()</code> multiple times
Step-by-Step Solution
Solution:
  1. Step 1: Understand message sending behavior

    produce() queues messages asynchronously. Calling it multiple times queues multiple messages.
  2. Step 2: Use flush() to wait for delivery

    Calling flush() once after all produce() calls waits for all messages to be sent before program exit.
  3. Final Answer:

    Call produce() for each message, then call flush() once at the end -> Option A
  4. Quick Check:

    Produce many, flush once after all [OK]
Quick Trick: Flush once after all produce calls to wait [OK]
Common Mistakes:
MISTAKES
  • Flushing after every produce (slow)
  • Flushing before producing messages
  • Not flushing at all causing lost messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes