kafka⽣产者端dns配置与集端配置不⼀致问题:java.io.IOException。。。
背景描述:
在虚拟机集上搭建了zk、kafka(version:0.11)集,在控制台上测试⽣产消费时正常。⽽后在windows端使⽤java api向虚拟机消费端⽣产发送数据,发现程序正常运⾏起来过了⼤概⼗秒后结束( exit code 0),但在虚拟机开启的消费者端并没有收到数据。经过⼏次检查,确保通信没问题,在java api端给未创建的topic发送数据时还可以发现在kafka集端主动创建了这个topic。但发送的数据在虚拟机的控制台消费者端就是没有打印(测试将数据打印到控制台上的)。
相关代码:
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "chdp01:9092,chdp02:9092,chdp03:9092");
打开log4j debug发现以下错误:
2019-09-17 15:58:26,966 DEBUG [org.apache.kafka.clients.NetworkClient] - Initiating connection to node 1 at chdp11:9092.
2019-09-17 15:58:26,966 DEBUG [org.apache.kafka.clients.NetworkClient] - Error connecting to node 1 at chdp11:9092:
java.io.IOException: Can't resolve address: chdp11:9092
at org.apache.t(Selector.java:195)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:762)
at org.apache.kafka.ady(NetworkClient.java:224)
at org.apache.kafka.clients.producer.internals.Sender.sendProducerData(Sender.java:247)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:223)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:175)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.t(SocketChannelImpl.java:622)
at org.apache.t(Selector.java:192)
... 6 more
2019-09-17 15:58:26,966 DEBUG [org.apache.kafka.clients.NetworkClient] - Initialize connection to node 3 for sending metadata request
2019-09-17 15:58:26,966 DEBUG [org.apache.kafka.clients.NetworkClient] - Initiating connection to node 3 at chdp13:9092.
2019-09-17 15:58:26,966 DEBUG [org.apache.kafka.clients.NetworkClient] - Error connecting to node 3 at chdp13:9092:
java.io.IOException: Can't resolve address: chdp13:9092
at org.apache.t(Selector.java:195)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:762)
at org.apache.kafka.clients.NetworkClient.access$600(NetworkClient.java:60)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:906)
at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:817)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:430)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:224)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:175)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.channels.UnresolvedAddressException
nodeselectorat sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.t(SocketChannelImpl.java:622)
at org.apache.t(Selector.java:192)
... 8 more
抽取主要⼏⾏:
Error connecting to node 1 at chdp11:9092:
java.io.IOException: Can't resolve address: chdp11:9092
。。。
Caused by: java.nio.channels.UnresolvedAddressException
再来看⼀下windows与虚拟机上的相关dns配置
虚拟机dns(/etc/hosts)
192.168.11.11 chdp11
192.168.11.12 chdp12
192.168.11.13 chdp13
windows(C:\Windows\System32\drivers\etc\hosts)
192.168.11.11 chdp01
192.168.11.12 chdp02
192.168.11.13 chdp03
仔细看看这两个dns配置的ip与域名。
因为⽇常学习测试的原因在⾃⼰电脑上搭建了好⼏套虚拟机,每套虚拟机的命名都不⼀样但ip⼀样(为了避免每次去修改windows host⽂件这⾥偷了个懒)。
很明显了,在java api运⾏建⽴tcp连接时(三次握⼿)还会去查看运⽤kafka服务节点所在的dns,⽽这个dns在windows本地是没有配置的,故⽽就出现了UnresolvedAddressException这个让⼈看起来有点奇怪的异常(我在windows通信⽤的dns没这个呀,这不是在虚拟机上配置的dns吗。。。)
此外org.s.TimeoutException:也可能有该问题引起。
将windows上的dns映射域名修改为与虚拟机⼀致问题解决
192.168.11.11 chdp11
192.168.11.12 chdp12
192.168.11.13 chdp13

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。