kafka发送数据报错: Error connecting to node xxxxx:9092 (id: 1 rack: null)java.net.UnknownHostExceptio

这篇具有很好参考价值的文章主要介绍了kafka发送数据报错: Error connecting to node xxxxx:9092 (id: 1 rack: null)java.net.UnknownHostExceptio。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

报错内容:

warn报错:

 [kafka-producer-network-thread | producer-1] WARN  org.apache.kafka.clients.NetworkClient - [Producer clientId=producer-1] Error connecting to node xxxxx:9092 (id: 1 rack: null)
java.net.UnknownHostException: xxxxx
    at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797)
    at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1519)
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1378)
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1306)
    at org.apache.kafka.clients.DefaultHostResolver.resolve(DefaultHostResolver.java:27)
    at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:111)
    at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.currentAddress(ClusterConnectionStates.java:512)
    at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.access$200(ClusterConnectionStates.java:466)
    at org.apache.kafka.clients.ClusterConnectionStates.currentAddress(ClusterConnectionStates.java:172)
    at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:985)
    at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:311)
    at org.apache.kafka.clients.producer.internals.Sender.sendProducerData(Sender.java:353)
    at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:326)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:242)
    at java.base/java.lang.Thread.run(Thread.java:829)

error日志:

[kafka-producer-network-thread | producer-1] ERROR org.apache.kafka.clients.producer.internals.Sender - [Producer clientId=producer-1] Uncaught error in kafka producer I/O thread: 
java.lang.IllegalStateException: No entry found for connection 1
    at org.apache.kafka.clients.ClusterConnectionStates.nodeState(ClusterConnectionStates.java:330)
    at org.apache.kafka.clients.ClusterConnectionStates.disconnected(ClusterConnectionStates.java:134)
    at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:921)
    at org.apache.kafka.clients.NetworkClient.access$700(NetworkClient.java:67)
    at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:1086)
    at org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:971)
    at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:533)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:309)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:233)
    at java.base/java.lang.Thread.run(Thread.java:829) 

本质原因是kafka配置文件server.properites中默认监听hostname:

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092 
#advertised.listeners=PLAINTEXT://192.34.12.12:9092

两种解决方案

1.修改kafka服务的配置文件,改为监听ip,将 advertised.listeners 中的your.host.name 改为服务器的IP地址即可:

#advertised.listeners=PLAINTEXT://your.host.name:9092 
advertised.listeners=PLAINTEXT://192.34.12.12:9092

2.修改producer客户端所在的电脑的host文件,在host文件中添加如下信息:

192.34.12.12     xxxxx文章来源地址https://www.toymoban.com/news/detail-479086.html

到了这里,关于kafka发送数据报错: Error connecting to node xxxxx:9092 (id: 1 rack: null)java.net.UnknownHostExceptio的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包