#
Create Kafka Topic (from CLI)
This tutorial explains to you how to create a Kafka topic from CLI on Linux. This tutorial has an example as well.
In order to create a Kafka Topic you have to run the following command:
kafka-topics.sh --create \
--topic my-topic1 \
--replication-factor 2 \
--partitions 2 \
--zookeeper localhost:2181/kafka
Attention:
kafka-topics.sh must be defined in PATH environment variable
This topic has the name my-topic1
This topic has 2 partitions (Partition 0 and Partition 1)
We have 2 replicas for each partition like in the image below
At any time only one Broker can be a leader for a given Partition
Only that leader can receive and serve data for a Partition and the other Brokers will synchronize the data
Therefore, each Partition has one leader and multiple ISR (In-Sync-Replica)
When you connect to zookeeper to send a request, you could use any zookeeper server from the cluster:
If you want to see the topics list you can run the kafka-topics.sh --list --zookeeper localhost:2181/kafka
command: