Kafka createTopics 失败

问题描述 投票:0回答:2

我是 Kafka 新手,我正在尝试使用命令行创建一个主题,但它给了我以下错误:

  C:\kafka\bin\windows>kafka-topics.bat --create --topic tutorialspedia --bootstrap-server localhost:9092
    Error while executing topic command : Call(callName=createTopics, deadlineMs=1684812803022, tries=1, nextAllowedTryMs=1684812803141) timed out at 1684812803041 after 1 attempt(s)
    [2023-05-23 09:03:23,047] ERROR org.apache.kafka.common.errors.TimeoutException: Call(callName=createTopics, deadlineMs=1684812803022, tries=1, nextAllowedTryMs=1684812803141) timed out at 1684812803041 after 1 attempt(s)
    Caused by: org.apache.kafka.common.errors.DisconnectException: Cancelled createTopics request with correlation id 3 due to node 0

 being disconnected
 (kafka.admin.TopicCommand$)

我有 Zookeeper 和 Kafka 正在运行。

我也尝试按照其他帖子中建议的代码进行操作,但收到错误:

C:\kafka\bin\windows>kafka-topics --zookeeper 127.0.0.1:2181 --topics first_topic --create --partitions 3 --replication-factor 1
Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
        at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
        at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
        at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
        at joptsimple.OptionParser.parse(OptionParser.java:396)
        at kafka.admin.TopicCommand$TopicCommandOptions.<init>(TopicCommand.scala:567)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:47)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)

我错过了什么吗?

apache-kafka spring-kafka apache-zookeeper apache-kafka-connect kafka-topic
2个回答
2
投票

自 Kafka 3.0 起,

--zookeeper
选项已被删除。您现在需要使用
-bootstrap-server
来指定
kafka-topics
命令应使用的 Kafka 代理。

例如:

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

请注意,主题名称的正确标志是

--topic
(而不是
--topics
)。


0
投票

我花了一个多小时,我发现解决方案是 取消 server.properties 中以下行的注释

听众=明文://localhost:9092

然后运行

. 在\windows\kafka-topics.bat --create --topic topic-example1 --bootstrap-server localhost:9092

© www.soinside.com 2019 - 2024. All rights reserved.