Kafka Set Up and Terminal Command For Producer And Consumer
Posted By : Gopal Tanwar | 24-Feb-2018
In this blog, we learn about Kafka setup, some core concept of Kafka and some terminal command related to Kafka producer and consumer.
In this blog, we cover below command,
a. Set up of
c. How to create a
e. How to send some message to
Before starting the terminal command we have to understand some core concept of Kafka.
Consumer:- In Kafka consumer is an application who read data from Kafka server.
Broker:- Producer and consumer don't communicate directly they need
who help them to communicate with each other.
Topic:- Topic is a unique name for Kafka stream. If producer wants to send some data first it should have some topic where to store the data
same apply for producer it should have some topic from where to read the data.
a. First, we have to download the Kafka, you can download it from below link.
b. Extract it and open terminal
c. Kafka uses ZooKeeper so you need to first start a ZooKeeper server for this go to terminal and type below command.
- bin/zookeeper-server-start.sh config/zookeeper.properties
* When you start the ZooKeeper at the end it will show the port number just remember the port number, we will use this in some next command.
d. Now ZooKeeper is started after this we have to start Kafka server for this you have to type below command.
e. After start Kafka server we have to create a topic with some name in which we have to store the data.
* here the first topic is the topic name
* 2181 is the port number when we start the ZooKeeper
f. You can see all topic name with the below command
* It will show you all the topic name which
g. After creating topic its time to produce some data on that topic. Produce means you have to store some data on that topic
For this, you have to type the below command
* By this command your producer is starting after this type message into the console to send to the server.
* 9092 is your Kafka server port number you can see this port number on the server.properties inside config folder.
h. Now it's time to consume the data which we produce by consuming we mean to read data from the server.
For this, you have to type command. And also open a new terminal.
- bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic firstTopic --from-beginning
That's it congrats you learn some important command of Kafka.