23

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)?

4 Answers 4

30

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.


enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

It is weird, the kafka-topic.sh spec states the partitions param is optional but its actually NOT...
9

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

2 Comments

Using version 2.13-2.6.0 and option --bootstrap-server server:port it in fact takes the number of partitions defined in the property num.partitions.
Step 3 of the quickstart suggests that partitions and replication-factor are optional kafka.apache.org/quickstart Also, the options list provided by bin/kafka-topics.sh explicitly mentions that " If not supplied for create, defaults to the cluster default." (kafka_2.13-3.0.0)
3

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 

Comments

0

🙌 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.