1. 程式人生 > >Kafka java Client 錯誤 org.apache.kafka.clients.NetworkClient Error connecting to node 1 at slave2:909

Kafka java Client 錯誤 org.apache.kafka.clients.NetworkClient Error connecting to node 1 at slave2:909

開發環境:win10+Eclipse
伺服器:centos+kafka0.10.2


錯誤:

[2017-09-09 13:34:40,648] [DEBUG] org.apache.kafka.clients.NetworkClient Initiating connection to node 1 at slave2:9092. 
[2017-09-09 13:34:40,648] [DEBUG] org.apache.kafka.clients.NetworkClient Error connecting to node 1 at slave2:9092: 
java.io.IOException: Can't resolve address: slave2:9092
at org.apache.kafka.common.network.Selector.connect(Selector.java:182) at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:629) at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:186) at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:184
) at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:139) at java.lang.Thread.run(Unknown Source) Caused by: java.nio.channels.UnresolvedAddressException at sun.nio.ch.Net.checkAddress(Unknown Source) at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) at org.apache.kafka.common.network.Selector.connect(Selector.java:179
) ... 5 more

解決方案:
在開發環境的hosts檔案中新增解析

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
192.168.17.13 slave1
192.168.17.14 slave2
192.168.17.15 slave3