错误如下:
java.io.IOException: Can't resolve address: ds105.usw2.location.io:19092
at org.apache.kafka.common.network.Selector.doConnect(Selector.java:235) ~[kafka-clients-2.0.0.jar:na]
at org.apache.kafka.common.network.Selector.connect(Selector.java:214) ~[kafka-clients-2.0.0.jar:na]
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:864) [kafka-clients-2.0.0.jar:na]
at org.apache.kafka.clients.NetworkClient.access$700(NetworkClient.java:64) [kafka-clients-2.0.0.jar:na]
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:1035) [kafka]
Caused by: java.nio.channels.UnresolvedAddressException: null
分析原因
Can't resolve address? 无法解析地址,首先排查,是否是集群问题?
1.首先使用jps查看kafka与zookeeper是否正常启动
[root@ppp_m_db base]# jps
24672 QuorumPeerMain
30656 Kafka
12482 Bootstrap //zookerper
16985 MycatStartup
36428 MycatStartup
27372 jar
5694 Jps
2.查看各个zookeeper的状态
[root@ppp_m_db bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /ppp/base/zookeeper/bin/../conf/zoo.cfg
Mode: follower
//能正常获取各个zookeeper节点的Mode类型,为Master或者follower,则接下来排除kafka
3.查看kafka的状态,多数为使用命令查看,如查看集群中各topics的状态
root@ppp_m_db bin]# ./kafka-topics.sh --describe --zookeeper 10.212.130.5:12181
Topic:I PartitionCount:1 ReplicationFactor:2 Configs:
Topic: I Partition: 0 Leader: 2 Replicas: 2,0 Isr: 2,0
Topic:IF_LEAPSEC PartitionCount:1 ReplicationFactor:2 Configs:
Topic: IF_LEAPSEC Partition: 0 Leader: 0 Replicas: 0,1 Isr: 0
//有结果则表明kafka集群运行正常
4.接下来查看是否是网络问题,根据后台报错,是无法解析主机名,那尝试在本地配置云服务kafka的IP+域名
配置Hosts中的IP与域名
1.文件目录是C:\Windows\System32\drivers\etc
在hosts文件中添加IP与域名
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
0.0.0.0 account.jetbrains.com
35.163.126.244 ds99.usw2.location.io //云服务器kafka节点配置
52.25.155.233 ds105.usw2.location.io
52.27.244.78 ds106.usw2.location.io
重新编译或者运行项目,则发现错误已解决