What is Kafka? How Kafka works?Instllation steps.

What is Apache Kafka?
Apache Kafka is an open-source distributed streaming platform that ingests and processes streaming data in real-time. It is designed to handle a high volume of data from different sources. Apache Kafka uses a Publish and Subscribe model to read and write streams of records. Kafka reads and writes messages asynchronously.

Topics: Kafka topics is a feed name to which messages are published. It is used to organize and categorize in a distributed and scalable manner.
Its logical categorization of messages in Kafka

Partition: A topic can be divided into multiple partitions which allows for parallelism & scalability. Each partition is an ordered and immutable sequence of records
Producer / Publisher: are clients who generate messages and queue them into the Kafka model.
Consumer / Subscriber: are ones who consume messages from the Kafka model

Prerequisite:
Download & install JDK

Image description

Java -version

Image description

Download the kafka latest stable version from official Apache websites.

Image description

Extract the tgz file as below
tar xvfz kafka_2.12-3.4.0.tgz
Rename the kafka directory & put it in opt/kafka directory.
mv kafka_2.12-3.4.0 kafka
/opt/kafka/bin

Before starting kafka we need to start the zookeeper.
Run the following commands in order to start all services in the correct order:

/opt/kafka$ bin/zookeeper-server-start.sh config/zookeeper.properties

Start the kafka server.
/opt/kafka$ bin/kafka-server-start.sh config/server.properties
These services will be running on Linux active prompt .to run it as systemd services so that when you restart Linux these services will be restarted automatically.
Now create a service file for both Kafka & zookeeper

sudo vi /etc/systemd/system/zookeeper.service

Image description

Same for kafka

Image description

enable the service for systemd & realod the daemon

sudo systemctl daemon-reload
sudo systemctl start zookeeper to check sudo systemctl status zookeeper
sudo systemctl start kafka

Topic creation
bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
Created topic test.

to check if the topic is created

Image description

Congratulations,Kafka is installed in system & topic is created.
Now we can publish & consume messages