【发布时间】:2016-08-16 02:55:54
【问题描述】:
我有一个运行 zookeeper 和 kafka 的 AWS EC2 ubuntu 实例。我想从我的计算机连接到 kafka,所以我有一个 Java 应用程序,我在其中使用 kafka api 进行连接。当我(从 Eclipse)运行应用程序时,出现以下错误:
log4j:WARN No appenders could be found for logger (kafka.consumer.SimpleConsumer).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "Timer-0" java.net.ConnectException: Connection refused
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:484)
at sun.nio.ch.Net.connect(Net.java:476)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:675)
at kafka.consumer.SimpleConsumer.connect(SimpleConsumer.scala:49)
at kafka.consumer.SimpleConsumer.getOrMakeConnection(SimpleConsumer.scala:186)
at kafka.consumer.SimpleConsumer.fetch(SimpleConsumer.scala:79)
at kafka.javaapi.consumer.SimpleConsumer.fetch(SimpleConsumer.scala:43)
似乎这行正在抛出错误:
FetchRequest req = new FetchRequest("test", 0, offset, 1000);
ByteBufferMessageSet messageSet = simpleConsumer.fetch(req);
在控制台中也提到了一些关于 log4j 的信息。我在实例中有 log4j.properties 文件,以及其他 kafka 配置文件。我不知道这是导致此错误的原因还是配置中的其他原因。我尝试将hostname 更改为server.properties 中的我的公共IP 地址,并与producer.properties 中的broker.list 相同。
我使用的是 kafka 0.7.2 版本。
【问题讨论】:
-
是什么让您断定连接不起作用?什么是服务服务器端口?您是否尝试过 telnet 到端口以确保它已打开?您是否设置了 EC2 安全组以允许从该特定端口进行连接。
-
我收到那个错误,它说连接被拒绝。默认的 kafka 端口 (9092) 是打开的(使用
netstat -tlnp),我可以看到该端口正在侦听,并且在安全组中我打开了该端口。 -
java.net.ConnectException: Connection denied ,意味着一些事情:服务没有启动; secgrp 未配置;服务拒绝连接等。重要的是使用 netcat 获取准确的消息,在 API 之前修复连接。
标签: java eclipse amazon-web-services amazon-ec2 apache-kafka