nerdexam
Confluent

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…

Developing Kafka Producers

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)
  • A
    4% (1)
  • C
    92% (24)
  • D
    4% (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>) - ProducerRecord is 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

#producer API#Future#RecordMetadata#Java API

Community Discussion

No community discussion yet for this question.

Full CCDAK Practice