简体   繁体   中英

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. I want to connect to kafka from my computer so I have a Java application where I do the connection using kafka api. When I run the application (from Eclipse) I get the following error:

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. I have the log4j.properties file in the instance, with the other kafka configuration files. 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 .

I'm using kafka 0.7.2 version.

It's solved. There was a line in my code trying to connect to localhost instead of the instance public IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM