CCDAK · Question #63
What is returned by a producer.send() call in the Java API?
The correct answer is C. Future<RecordMetadata> object. producer.send() in the Kafka Java API returns a Future<RecordMetadata> because sending is asynchronous - the call dispatches the record to an internal buffer and returns immediately with a future you can block on or attach a callback to. RecordMetadata contains the topic…
Question
What is returned by a producer.send() call in the Java API?
Options
- AFuture<ProducerRecord> object
- BA Boolean indicating if the call succeeded
- CFuture<RecordMetadata> object
- DUnit
How the community answered
(26 responses)- A4% (1)
- C92% (24)
- D4% (1)
Explanation
producer.send() in the Kafka Java API returns a Future<RecordMetadata> because sending is asynchronous - the call dispatches the record to an internal buffer and returns immediately with a future you can block on or attach a callback to. RecordMetadata contains the topic, partition, and offset where the record was actually written, which Kafka only knows after broker acknowledgment.
Why the distractors are wrong:
- A (
Future<ProducerRecord>) -ProducerRecordis the input type (what you send), not the result. The future holds metadata about where it landed, not a copy of what you sent. - B (Boolean) - Kafka's async model doesn't reduce to a simple pass/fail boolean; you get structured metadata or an exception via the future.
- D (Unit) -
send()is not fire-and-forget void; it explicitly returns the future so callers can optionally confirm delivery.
Memory tip: Think "send → future of where it went." You sent a ProducerRecord in, and you get back metadata about its destination (partition + offset) out - hence Future<RecordMetadata>.
Topics
Community Discussion
No community discussion yet for this question.