我正在尝试通过SimpleConsumer连接到远程kafka zookeeper(zookeeperhost:1234
),并为我指定的主题提取元数据。但是,我收到此错误:
RunnerMain failed :java.io.EOFException: Received -1 when reading from channel, socket has likely been closed.
我运行telnet zookeeperhost 1234并得到以下信息:
Trying <ip addr of host>...
Connected to zookeeperhost.somedomain.com.
Escape character is '^]'.
因此,看来我能够联系到服务,没有安全/权限问题。
这是我的代码:
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领导者代理(默认情况下为端口9092),而不是Zookeeper。检查此链接以获取有关如何使用SimpleConsumer的详细信息:https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+SimpleConsumer+Example
关于java - Kafka SimpleConsumer无法连接到Zookeeper : Received -1 when reading from channel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30519466/