从通道读取时收到

从通道读取时收到

本文介绍了Kafka SimpleConsumer 无法连接到 zookeeper:从通道读取时收到 -1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 SimpleConsumer 连接到远程 kafka zookeeper (zookeeperhost:1234),并为我指定的主题提取元数据.但是,我收到此错误:

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.

我运行 telnet zookeeperhost 1234 并得到以下结果:

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.

这是我的代码:

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();

推荐答案

您需要将 SimpleConsumer 连接到 kafka leader broker(默认为 9092 端口)而不是 zookeeper.查看此链接了解如何使用 SimpleConsumer:https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+SimpleConsumer+Example

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

这篇关于Kafka SimpleConsumer 无法连接到 zookeeper:从通道读取时收到 -1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:02