简体   繁体   中英

Kafka create topic with default number of partitions

I am trying to create a new Kafka topic from the command line

$ kafka-topics --create --zookeeper localhost:2181 --topic def-test 

In kafka CLI , the number of partitions is a mandatory option. The num.partitions is the default partitions for auto created topics.

One thing you can do is , enable auto topic creation using prop "auto.create.topics.enable" and then whenever there is a fetch or produce request for a non-existent topic, it will be auto created with the default partitions

I was trying the quickstart guide of Kafka and was facing this issue. As the guide suggests, I ran the following command,

$ bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092

and got the following error:

Missing required argument "[partitions]"

As the error clearly states, we need to add more arguments to the command we use. For this you need to add --partitions 1 . After this is added you will get the following error.

Missing required argument "[replication-factor]"

Do the same to this as well. Add the flag --replication-factor 1 . So finally my command would look like

bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1

I hope this helps someone who is stuck with the quickstart guide. More on what these flags mean is given below.


在此处输入图片说明 在此处输入图片说明

You must add partitions and replication-factor too (not mentioned in the official doc.)

eg: --partitions 3 --replication-factor 1 , so:

bin/kafka-topics.sh --create --topic test-topic --partitions 3 --replication-factor 1 --bootstrap-server localhost:9092

🙌 Even if you have such an error, your topic was created. You can check this with such command:

bin/kafka-topics.sh --list --bootstrap-server localhost:9092

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM