Create Apache Kafka Consumer

To create an Apache Kafka consumer, you will need to first install Apache Kafka on your system, if you haven’t already done so. You can download Apache Kafka from the official website (https://kafka.apache.org/downloads). Once you have installed Apache Kafka, you can create a consumer by following these steps:

  • Open a new terminal and navigate to the directory where Apache Kafka is installed.
  • Run the following command to start the Apache Kafka server:
kafka-server-start config/server.properties
  • Open another terminal and navigate to the directory where Apache Kafka is installed.
  • Run the following command to create a new topic called “my-topic”:
kafka-topics --bootstrap-server localhost:9092 --topic first-topic --create
kafka-topics --bootstrap-server localhost:2181 --replication-factor 1 --partitions 1 --topic my-topic
  • Run the following command to start a consumer that listens to the “my-topic” topic:
kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --from-beginning

This will start a consumer that listens to the “my-topic” topic and prints any messages that are published to that topic to the terminal. You can then publish messages to the “my-topic” topic using a Kafka producer, and the consumer will receive and print those messages.

Kafka Image from https://www.oreilly.com/

Written by

Sergii Demianchuk

Applications Architect