问题
docker 容器日志报java.io.IOException: Can't resolve address: node04:9092
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_272]
Caused by: java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Net.java:104) ~[na:1.8.0_272]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:621) ~[na:1.8.0_272]
at org.apache.kafka.common.network.Selector.doConnect(Selector.java:233) ~[kafka-clients-2.0.1.jar!/:na]
... 19 common frames omitted
2021-02-07 14:54:07.591 WARN 6 --- [ntainer#3-0-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-4, groupId=databank-broker2] Error connecting to node node04:9092 (id: 189 rack: null)
java.io.IOException: Can't resolve address: node04:9092
at org.apache.kafka.common.network.Selector.doConnect(Selector.java:235) ~[kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.common.network.Selector.connect(Selector.java:214) ~[kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:864) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:265) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.trySend(ConsumerNetworkClient.java:485) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:261) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:242) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:218) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.AbstractCoordinator.ensureCoordinatorReady(AbstractCoordinator.java:230) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.poll(ConsumerCoordinator.java:314) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.updateAssignmentbroker2IfNeeded(KafkaConsumer.java:1218) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1175) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1154) [kafka-clients-2.0.1.jar!/:na]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:742) [spring-kafka-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:699) [spring-kafka-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_272]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_272]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_272]
Caused by: java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Net.java:104) ~[na:1.8.0_272]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:621) ~[na:1.8.0_272]
at org.apache.kafka.common.network.Selector.doConnect(Selector.java:233) ~[kafka-clients-2.0.1.jar!/:na]
... 17 common frames omitted
2021-02-07 14:54:07.592 WARN 6 --- [ntainer#1-0-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-8, groupId=databank-broker2] Error connecting to node node05:9092 (id: 187 rack: null)
java.io.IOException: Can't resolve address: node05:9092
at org.apache.kafka.common.network.Selector.doConnect(Selector.java:235) ~[kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.common.network.Selector.connect(Selector.java:214) ~[kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:864) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:265) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.trySend(ConsumerNetworkClient.java:485) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:261) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:242) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:218) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.AbstractCoordinator.ensureCoordinatorReady(AbstractCoordinator.java:230) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.poll(ConsumerCoordinator.java:314) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.updateAssignmentbroker2IfNeeded(KafkaConsumer.java:1218) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1175) [kafka-clients-2.0.1.jar!/:na]
at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1154) [kafka-clients-2.0.1.jar!/:na]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:742) [spring-kafka-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:699) [spring-kafka-2.2.4.RELEASE.jar!/:2.2.4.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_272]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_272]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_272]
Caused by: java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Net.java:104) ~[na:1.8.0_272]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:621) ~[na:1.8.0_272]
at org.apache.kafka.common.network.Selector.doConnect(Selector.java:233) ~[kafka-clients-2.0.1.jar!/:na]
... 17 common frames omitted
本模块,连接的是cdh集群的kafka集群
解决方案
在cdh中搜索http://$(host_ip):7180/cmf/services/44/config#filterfreeText=kafka.p
在“kafka.properties 的 Kafka Broker 高级配置代码段(安全阀)”的列表中,每个broker节点,加入如下配置
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://196.168.6.18:9092
有几个对应的broker,添加几个,这样项目就可以正常连接cdh中的kafka集群了。