Kafka Consumer Examples Using Java: Apache Kafka is an open-source stream-processing software platform developed by LinkedIn and donated to the Apache Software Foundation, written in Scala and Java.

What is Kafka Consumer?

The consumer is used for the consumption of Kafka data inserted by Kafka Producer. The primary role of a Kafka consumer is to take Kafka connection and consumer properties to read records from the respective Kafka broker.

In this tutorial, we will see how to create a Kafka Consumer examples using java.

Create the maven project and add below dependencies to your POM file

Then Create Package and Create a class with Name SimpleConsumer.java

use below code

In the above code, records are displayed from offset Zero to modify the code to read records from current offset then use below code

the above code will work for getting the latest records from Kafka broker.

Run the above code to get all records or latest records from the Kafka server.

Thanks

Also Read: Kafka Producer Examples Using Java

Kafka Consumer Examples Using Java

Leave a Reply

Your email address will not be published. Required fields are marked *