Category : Apache Kafka | Sub Category : Apache Kafka | By Prasad Bonam Last updated: 2023-08-05 09:11:28 Viewed : 538
To create a Kafka topic with 3 partitions and a replication factor of 2, you can use the kafka-topics.sh
script (or kafka-topics.bat
on Windows) provided by Apache Kafka. Make sure you have Kafka installed and have started the Kafka brokers before running the following command.
Using the command-line tool on Unix/Linux/Mac:
bashbin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic my_topic --partitions 3 --replication-factor 2
Using the command-line tool on Windows:
batchbinwindowskafka-topics.bat --bootstrap-server localhost:9092 --create --topic my_topic --partitions 3 --replication-factor 2
Explanation:
In the above command, we are using the kafka-topics.sh
(or kafka-topics.bat
) script to create a Kafka topic named "my_topic." We specify the Kafka broker to connect to using the --bootstrap-server
option with the broker address localhost:9092
.
We want to create a topic with 3 partitions and a replication factor of 2. The --partitions
option sets the number of partitions for the topic to 3, and the --replication-factor
option sets the replication factor to 2.
After executing the command, Kafka will create the "my_topic" topic with 3 partitions and replicate each partition across two brokers to ensure high availability and fault tolerance.