Since Spring Kafka 3.0 it is a CompletableFuture rather than a ListenableFuture.
kafkaTemplate.send("orders", order.id(), payload)
.whenComplete((result, ex) -> {
if (ex != null) { log.error("send failed", ex); return; }
RecordMetadata md = result.getRecordMetadata();
log.info("sent to {}-{} offset {}", md.topic(), md.partition(), md.offset());
});
sent to orders-3 offset 118
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