sudo apt update && sudo apt upgrade
sudo apt install default-jre wget git unzip -y
sudo apt install default-jdk -y
wget http://www-us.apache.org/dist/kafka/2.7.0/kafka_2.13-2.7.0.tgz
sudo mkdir /usr/local/kafka && cd /usr/local/kafka
sudo tar -xvzf ~/kafka_2.13-2.7.0.tgzz --strip 1
Update the kafka path in below two files :
sudo vi /etc/systemd/system/zookeeper.service
sudo vi /etc/systemd/system/kafka.service
sudo systemctl daemon-reload
sudo systemctl enable --now zookeeper
sudo systemctl enable --now kafka
sudo systemctl status kafka zookeeper
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic myKafkaCluster
sudo systemctl start zookeeper
sudo systemctl start kafka
sudo systemctl status kafka
Craete topic
cd /usr/local/kafka
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testTopic
List of topics
bin/kafka-topics.sh --list --zookeeper localhost:2181
Send and Receive Messages in Kafka
Send
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic
REcieve
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning