Add kafka topics

Published by Murali Basani on

Add one kafka topic with 2 replicas and 4 partitions with the below command

<kafka_installation>/bin/kafka-topics --create --zookeeper <zkhosts> --topic <topicname> --replication-factor 2 --partitions 4

Example : /opt/kafka/bin/kafka-topics --create --zookeeper host1:2181,host2:2181,host3:2181/new --topic testtopic --replication-factor 2 --partitions 4

Add multiple kafka topics with 2 replicas and 4 partitions with the below command

Create new file topics.txt with the below like content(topic names)

testtopic1
testtopic2
testtopic3

Command (on linux)

cat topics.txt | xargs -n1 /opt/kafka/bin/kafka-topics --create --zookeeper host1:2181 --topic testtopic --replication-factor 2 --partitions 4

Leave a Reply

Your email address will not be published. Required fields are marked *