apache kafka tutorial

zookeeper is not a recognized option while running kafka-console-consumer.sh

This tutorial guides you on how to fix zookeeper is not a recognized option while running kafka-console-consumer.sh script to consume messages from a Kafka topic.

zookeeper is not a recognized option – Issue

I configured Java and Zookeeper on my ubuntu machine on Google Cloud. Then I installed Kafka Server, configured it and started it to store message log segments using the following command.

$ sudo /usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties

Once server is started, wanted to verify that setup is working fine. Therefore, tried to create a test topic, produced messages and consume the same.

As a first step, created a topic called “test” topic by executing the following command.

$ /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic test.

Next, verified the topic created.

$ sudo /usr/local/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test
Topic: test     PartitionCount: 1       ReplicationFactor: 1    Configs:
        Topic: test     Partition: 0    Leader: 0       Replicas: 0     Isr: 0

Then, produced messages to the test topic as shown below.

$ sudo /usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
>Test msg 1
>Test msg 2
>Test msg 3
>Test msg 4

Finally, tried to consume messages from the topic “test” by executing the following command. But it resulted in throwing message which says “zookeeper is not a recognized option” as shown below.

$ sudo /usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
zookeeper is not a recognized option

Fix – zookeeper is not a recognized option

After looking at the Apache Kafka documentation, I came to know that the option –zookeeper is deprecated and need to use –bootstrap-server instead as shown below.

$ sudo /usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
Test msg 1
Test msg 2
Test msg 3
Test msg 4
^C
Processed a total of 4 messages
$

Note, you need to be sudo user to run the above commands.

That’s it. You had learnt how to fix zookeeper is not a recognized option issue while executing kafka-console-consumer.sh script to consume messages from a Kafka topic.

Hope it helped 🙂

References

guest
0 Comments
Inline Feedbacks
View all comments