How to install Apache Kafka on localhost

This tutorial assumes you are starting fresh and have no existing Kafka or ZooKeeper data.

Refer: https://kafka.apache.org/quickstart

Install and start Kafka

# 1. Download Kafka and Install
wget http://ftp.jaist.ac.jp/pub/apache/kafka/2.2.0/kafka_2.12-2.2.0.tgz
tar -xzf kafka_2.12-2.2.0.tgz
cd kafka_2.12-2.2.0
# 2. Start Zookeeper server (in new terminal)
bin/zookeeper-server-start.sh config/zookeeper.properties &
# 3. Start Kafka server (in new terminal)
bin/kafka-server-start.sh config/server.properties &

Use any features of Kafka

Create a topic

# Create topic with named "test"
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic
# See topic test
bin/kafka-topics.sh --list --bootstrap-server localhost:9092 test

Send some messages

Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default, each line will be sent as a separate message.

Run the producer and then type a few messages into the console to send to the server.

> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
Message 1
Message 2

Start a consumer

Kafka also has a command line consumer that will dump out messages to standard output.

> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
Message 1
Message 2

If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.

All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.

Sliding Sidebar

About Me

About Me

Hello, my name is Dũng (Johnny). Welcome to my blog.

As I’m a developer, I write about topics related to the field of programming, mainly from a technical point of view. On this blog you’ll find posts which encourage discussion, information about development trends, case studies, reviews, tutorials, tips on how to improve your effectiveness, and anything else that might be fascinating to people from the IT industry.
I love PHP, NodeJS, Java,... and Fullstack.