'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
I get the error
Missing required argument "[partitions]"
From the docs, I see that setting num.partitions, should have done the trick. I have the following in my server.properties
# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=2
But it is not taking effect. Also, I wonder how kafka-topics command which connects only to zookeeper and does not take any arguments to server.properties is going to be able to pick the correct value. How can I create topics without having to specify the number of partitions (by falling back to a default value specified elsewhere)?
Solution 1:[1]
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.
Solution 2:[2]
You must add partitions and replication-factor too (not mentioned in the official doc.)
e.g.: --partitions 3 --replication-factor 1 , so:
bin/kafka-topics.sh --create --topic test-topic --partitions 3 --replication-factor 1 --bootstrap-server localhost:9092
Solution 3:[3]
? 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
Finally, yes this is optional. But implementation is a little bit confusing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Keet Sugathadasa |
| Solution 2 | MauroB |
| Solution 3 | fanni |


