[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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store