[英]Connection refused while trying to connect to Kafka in AWS EC2
I have an AWS EC2 ubuntu instance where it's running zookeeper and kafka.我有一个 AWS EC2 ubuntu 实例,它运行 zookeeper 和 kafka。 I want to connect to kafka from my computer so I have a Java application where I do the connection using kafka api.
我想从我的计算机连接到 kafka,所以我有一个 Java 应用程序,我在其中使用 kafka api 进行连接。 When I run the application (from Eclipse) I get the following error:
当我运行应用程序(从 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)
It seems like this lines are throwing the error:似乎这行正在抛出错误:
FetchRequest req = new FetchRequest("test", 0, offset, 1000);
ByteBufferMessageSet messageSet = simpleConsumer.fetch(req);
Also in the console it says something about log4j.同样在控制台中,它说了一些关于 log4j 的内容。 I have the
log4j.properties
file in the instance, with the other kafka configuration files.我在实例中有
log4j.properties
文件,以及其他 kafka 配置文件。 I don't know if it is what is causing this error or if it is something else from the configuration.我不知道是什么导致了这个错误,或者是配置中的其他东西。 I've tried to change
hostname
to my public IP address in server.properties
and the same with broker.list
in producer.properties
.我试图改变
hostname
到我的公网IP地址server.properties
和相同broker.list
在producer.properties
。
I'm using kafka 0.7.2 version.我正在使用 kafka 0.7.2 版本。
It's solved.解决了。 There was a line in my code trying to connect to localhost instead of the instance public IP.
我的代码中有一行试图连接到 localhost 而不是实例公共 IP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.