How to create a Callback for Kafka Producer


Blocking send method is suitable for the scenarios where your messages are produced at the slower pace. Asynchronous sends are more efficient as the producer can leverage grouping multiple messages and optimise network roundtrips to achieve better throughput. In high throughput use cases, you can supply a call-back method to your producer to be invoked when the acknowledgment arrives. Let’s create an example for the same.
We want to take the Hello Producer example and implement a call back method to the producer. The call back method should log the errors and success condition.
This example is an excerpt from the Book Kafka Streams – Real-time Stream Processing
For a detailed explanation of the example and much more, you can get access to the Book using below link.


Solution - Call-back Producer

Implementing a call-back is as simple as passing a lambda function to the send() method. The code snippet shown below demonstrates an example for the same.


You can access fully function project in our GitHub folder.

Read More

Author : Prashant Pandey -



You will also like:


What is Bastion Host?

What is Bastion Host? Learn Why and How of Bastion Server.

Learning Journal

What is Kafka?

Apache Kafka comes in three flavours. Learn all from experts.

Learning Journal

HTML5 Editors

The most popular and commonly used HTML5 code editors.

Learning Journal

Pure Function benefits

Pure Functions are used heavily in functional programming. Learn Why?

Learning Journal

Free virtual machines

Get upto six free VMs in Google Cloud and learn Bigdata.

Learning Journal

Streaming Concepts

Let us look at the area concerning the collection and processing of big data streams.

Learning Journal