Sourav Das
Sourav Das

Reputation: 103

Kafka console consumer not able to connect to zookeeper server on AWS EC2 server

I have installed kafka along with zookeeper in a single AWS EC2 instance. I have changed the hostname of the server to kafka. When I create topic it runs fine:

/home/kafka/kafka/bin/kafka-topics.sh --create --zookeeper kafka:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".

kafka-console-producer.sh also runs fine:

/home/kafka/kafka/bin# /home/kafka/kafka/bin/kafka-console-producer.sh --broker-list kafka:9092 --topic test
[2017-10-11 20:58:13,924] WARN Property topic is not valid (kafka.utils.VerifiableProperties)
testing

But the kafka producer is timing out:

ubuntu@kafka:~$ /home/kafka/kafka/bin/kafka-console-consumer.sh --zookeeper kafka:9092 --topic test --from-beginning
Exception in thread "main" org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 6000
at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:880)
at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:98)
at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:84)
at kafka.consumer.ZookeeperConsumerConnector.connectZk(ZookeeperConsumerConnector.scala:171)
at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:126)
at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:143)
at kafka.consumer.Consumer$.create(ConsumerConnector.scala:94)
at kafka.tools.ConsoleConsumer$.main(ConsoleConsumer.scala:145)
at kafka.tools.ConsoleConsumer.main(ConsoleConsumer.scala)

Kafka, zookeeper and the broker(one) is running on the same ec2 server and they have default configuration. Am I missing something in this installation?

Upvotes: 0

Views: 915

Answers (2)

vahid
vahid

Reputation: 1208

The issue is that when you use the old consumer (and use the --zookeeper argument) the ZooKeeper port should be provided (2181).

However, please note that the old consumer is now deprecated, and using the new consumer is highly recommended. Please see the answer by Mickael Maison for more info.

Upvotes: 1

Mickael Maison
Mickael Maison

Reputation: 26865

The new consumer (like the producer) does not connect to zookeeper anymore, it only connects to Kafka.

Replace --zookeeper in your command by --bootstrap-server:

/home/kafka/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 --topic test --from-beginning

Upvotes: 2

Related Questions