Bird
Raised Fist0

You want to ensure that your Kafka producer sends messages synchronously and waits for acknowledgment before proceeding. Which method should you use instead of send()?

hard🚀 Application Q9 of Q15
Kafka - with Java/Python
You want to ensure that your Kafka producer sends messages synchronously and waits for acknowledgment before proceeding. Which method should you use instead of send()?
AUse <code>send()</code> with a callback that blocks
BUse <code>send().get()</code> to block until the send completes
CUse <code>flush()</code> before send
DUse <code>sendSync()</code> method
Step-by-Step Solution
Solution:
  1. Step 1: Understand send() behavior

    send() is asynchronous and returns a Future object.
  2. Step 2: Use get() on Future to block

    Calling get() on the Future returned by send() blocks until the send completes, making it synchronous.
  3. Final Answer:

    Use send().get() to block until the send completes -> Option B
  4. Quick Check:

    send().get() makes send synchronous [OK]
Quick Trick: Call get() on send() Future to wait synchronously [OK]
Common Mistakes:
MISTAKES
  • Assuming sendSync() exists
  • Using flush() incorrectly
  • Blocking inside callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes