简体   繁体   English

"Kafka创建具有默认分区数的主题"

[英]Kafka create topic with default number of partitions

I am trying to create a new Kafka topic from the command line我正在尝试从命令行创建一个新的 Kafka 主题

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

In kafka CLI , the number of partitions is a mandatory option. 在kafka CLI中,分区数是必需选项。 The num.partitions is the default partitions for auto created topics. num.partitions是自动创建主题的默认分区。

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 您可以做的一件事是,使用prop“auto.create.topics.enable”启用自动主题创建,然后每当有对不存在的主题的获取或生成请求时,它将使用默认分区自动创建

I was trying the quickstart guide of Kafka and was facing this issue.我正在尝试Kafka快速入门指南并面临这个问题。 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 .为此,您需要添加--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 .添加标志--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:例如: --partitions 3 --replication-factor 1 ,所以:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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