Kafka: send() is asynchronous and returns a Future

Ignoring the result means never learning that the send failed.

Code
// Fire and forget - errors are invisible
producer.send(record);

// Callback - handle the failure
producer.send(record, (metadata, ex) -> {
    if (ex != null) log.error("send failed", ex);
    else log.info("{}-{}@{}", metadata.topic(), metadata.partition(), metadata.offset());
});

// Synchronous - blocks, kills throughput
producer.send(record).get();
Output
orders-3@118
The callback runs on the producer's I/O thread - do not block in it.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11