Member-only story
Kafka Consumer Example Using Java
In this article, we will see how to Consume records/messages from Topic. Let’s get to it!
In last article, we discussed how to how to produce records/messages with Kafka brokers. In this article, we will see how to consume records/messages from Topic.
Now, before creating a Kafka producer in java, we need to define the essential Project dependencies. In our project, there will be three dependencies required:
So After Generating the project we will extract this file and will import kafka-consumer project into Eclipse.
Here In this project we will create one KafkaMessageListener Class that will be used to consume the message from topic. This class will be annotated with the annotation @KafkaListener(id = “my-listener”, topics=”MyTopic”), we will define id for kafka listener and also define Topic name that will be subscribed by the consumer. On function level we will use @KafkaHandler annotation . So this function will receive the message.
After that we will create KafkaConsumerConfig.java class in package com.example.kafkaconsumer.config. Here we will define…