[Spring Boot] Unit Testing Kafka Producer with Producer Callback
This article covers how to write unit tests for Kafka Producers with callbacks. Callbacks can be useful to handle success cases and failure cases because Kafka Producers are asynchronous.
The
send()
method is asynchronous. When called it adds the record to a buffer of pending record sends and immediately returns. This allows the producer to batch together individual records for efficiency.
Implementation
Producer Callback
Producer
Unit Test
References: