63

I am new to kafka and zookepper, and I am trying to create a topic, but I am getting this error -

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:517)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:47)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)

I am using this command to create the topic -

.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partions 1 --topic TestTopic
1

6 Answers 6

156

Newer versions(2.2+) of Kafka no longer requires ZooKeeper connection string

--zookeeper localhost:2181

It throws the following exception while creating a topic

Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option

Instead, add Kafka Broker --bootstrap-server localhost:9092 connection string.

./kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 4
2
  • 5
    In my case in windows, it worked: kafka-topics.bat --create --topic test-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1
    – agileDev
    Commented Mar 17, 2022 at 8:29
  • kafka-topics.bat --bootstrap-server localhost:9092 --list ( for listing the topics ) Commented Sep 24, 2022 at 20:19
12

In the latest version kafka_2.12-3.1.0 (2022) after unzipping and setting the properties and logs. keep the Kafka folder on the C drive and always run the command prompt with 'run as administrator'. The .bat file is for windows

Terminal 1

C:\kafka\bin\windows>zookeeper-server-start.bat ..\..\config\zookeeper.properties

Terminal 2

C:\kafka\bin\windows>kafka-server-start.bat ..\..\config\server.properties

Terminal 3

C:\kafka\bin\windows>kafka-topics.bat --create --topic tutorialspedia --bootstrap-server localhost:9092

Created topic tutorialspedia.

To checklist of topic created

C:\kafka\bin\windows>kafka-topics.bat --list --bootstrap-server localhost:9092

tutorialspedia

3

Read the official Kafka documentation for the version you downloaded, and not some other blog/article that you might have copied the command from

zookeeper is almost never used for CLI commands in current versions

If you run bin\kafka-topics on its own with --help or no options, then it'll print the help messaging that shows all available arguments.

1

Kafka Created Topics for Windows:

kafka-topics.bat --create --topic learningkafka --bootstrap-server localhost:9092

After topic created we can check the kafka list:

kafka-topics.bat --list --bootstrap-server localhost:9092
1

It's not --partions, but --partitions (typo). Same like you, see this link: Exception: partition is not a recognized option, when creating a kafka topic inside a docker.

0

Kakfa create Topic :

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.