Apache Kafka Producer Console

Apache Kafka Producer Console

In this article, we will discuss how to publish a message by using the Apache Kafka Producer Console. Kafka having a command-line interface to publish and to consume messages from the topic. Here I will show you how to publish the message and text file from the Kafka Producer Console.

 

If Apache Kafka software not installed, please install it by seeing the article. Apache Kafka Installation of windows and Linux/Unix is the same. There is the only difference is .bat file for Windows system and .sh files for Linux system

Installation Summary Details

  • Kafka Installation home directory in Windows: D:\ApacheKafka-ZooKeeper\kafka
  • Kafka Installation home directory in Linux: /home/ApacheKafka-ZooKeeper/kafka
  • Kafka Default Port: 9092
  • Zookeeper Default Port: 2181

 

After installing the Apache Kafka, first up all you need to start the Zookeeper and then only start Apache Kafka.

For more Kafka commands, go through the Most important Apache Kafka Commands

Zookeeper Server Start:

Windows:

<Kafka-Home>\bin\windows> zookeeper-server-start.bat ..\..\config\zookeeper.properties     

Linux:

<Kafka-Home>\bin> zookeeper-server-start.sh ../../config/zookeeper.properties

Kafka Server Start:

Windows:

<Kafka-Home>\bin\windows> kafka-server-start.bat ..\..\config\server.properties

Linux:

<Kafka-Home>\bin> kafka-server-start.bat.sh ../../config/server.properties

Once the Kafka up and running, then go to <Kafka-Home>\bin\windows  for Windows and <Kafka-Home>/bin for Linux system

Kafka Producer Console

Suppose you have a topic i.e MyFirstTopic1. If not having, create the topic by using the following command.

Windows:

<Kafka-Home>\bin\windows>  kafka-topics.bat --zookeeper localhost:2181 --create --topic MyFirstTopic1 --partitions 1 --replication-factor 1     

Linux:

<Kafa-Home>\bin$ kafka-topics.sh --zookeeper localhost:2181 --create --topic MyFirstTopic1 --partitions 1 --replication-factor 1      

Here we have created topic name is MyFirstTopic1

We can open the producer console to publish the message by executing the following command.

Windows:

<Kafka-Home>\bin\windows> kafka-console-producer.bat --broker-list localhost:9092 --topic MyFirstTopic1     

Linux:

<Kafka-Home>\bin\windows> kafka-console-producer.sh--broker-list localhost:9092 --topic MyFirstTopic1

Kafka-Producer-Console

Kafka-Producer-Console

 

In the console, you can type the message and hit the enter button then the typed message will be published to the specified topic i.e MyFirstTopic1.

Kafka-Producer-Console-2

Kafka-Producer-Console-2

 

Here how to see the published message. The published message we can see through the consumer console.

 

Thank you for reading the article, please subscribe and get the latest article into your inbox.

 

 

 

Leave a Reply