Basic Kafka Consumer example in java
In this tutorial you will learn, how to make a simple kafka consumer, which sends records for ever.
You will learn the following :
- How to create topics
- How to create Kafka Consumer
- How to configure Kafka Properties
- How to subscribe to a topic
- How to poll infinitely with a consumer
You will learn how to create topics, how to create a Kafka consumer and how to configure it.
Also, you w
The first example shows how to print out records from Kafka to the console.
We will have to set the properties for a Kafka Consumer Object and create it.
Then we subscribe to the topics of our choice
Setting Properties
Java
Properties props = new Properties(); |
Create an Instance of a KafkaConsumer Object and call the subscribe() method to subscribe to some topics
KafkaConsumer |
Ask the consumer for new records continuously
while (true) { |