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.
Producer:- In
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.
Now,
a. First, we have to download the Kafka, you can download it from below link.
- https://kafka.apache.org/downloads
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.
- bin/
e. After start Kafka server we have to create a topic with some name in which we have to store the data.
- bin/
* 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
- bin/
* 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
- bin/
* 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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Gopal Tanwar
I am an explorer, I love to explore new technologies.I love making friends and love to explore new places.Always ready to help anybody anywhere.