Handling Producer Send Callbacks and Acknowledgments
Learn how to react to the outcome of asynchronous Kafka sends using callbacks, CompletableFuture, and acks configuration to guarantee delivery reliability.
Why Send Results Matter
When you call KafkaTemplate.send(), the message is dispatched asynchronously. The call returns immediately, but the broker may not have stored the record yet.
To build reliable producers you must inspect the result of each send so you can log, retry, or alert on failures.
The CompletableFuture Result
In Spring Kafka, send() returns a CompletableFuture<SendResult<K,V>>.
SendResultholds theRecordMetadata(partition, offset, timestamp).- You attach a continuation to handle success or failure.
CompletableFuture<SendResult<String,String>> future =
kafkaTemplate.send("orders", order.getId(), payload);All lessons in this course
- Integrating Spring Kafka Starter
- Sending Messages with KafkaTemplate
- Customizing Producer Configurations
- Handling Producer Send Callbacks and Acknowledgments