Kafka SimpleConsumer cannot connect to zookeeper : Received -1 when reading from channel

风流意气都作罢 提交于 2019-12-11 11:17:57

问题


I'm trying to connect to a remote kafka zookeeper (zookeeperhost:1234) via SimpleConsumer, and pulling metadata for the topics that I've specified. However, I get this error:

RunnerMain failed :java.io.EOFException: Received -1 when reading from channel, socket has likely been closed.

I ran telnet zookeeperhost 1234 and got the following:

Trying <ip addr of host>...
Connected to zookeeperhost.somedomain.com.
Escape character is '^]'.

So it looks like I am able to reach the service, there is no security/permission issue.

Here is my code:

SimpleConsumer consumer = new SimpleConsumer ("zookeeperhost", 1234, 100000, 64 * 1024, "leader_lookup");
List<String> topics = Collections.singletonList("some_event");
TopicMetadataRequest req = new TopicMetadataRequest(topics);
TopicMetadataResponse resp = consumer.send(req); //this is the line that is causing the error
List<TopicMetadata> metaData = resp.topicsMetadata();

回答1:


You need to connect SimpleConsumer to a kafka leader broker (port 9092 by default) not a zookeeper. Check this link for the details how to use SimpleConsumer: https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+SimpleConsumer+Example



来源:https://stackoverflow.com/questions/30519466/kafka-simpleconsumer-cannot-connect-to-zookeeper-received-1-when-reading-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!