kafka基礎:解決org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for xxx topic


https://my.oschina.net/kyle1970/blog/2396318/print

kafka 0.9.x以后的版本,有一個配置屬性叫advertised.listeners,在server.properties中,該屬性默認是注釋掉的,解釋如下:

#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://192.168.14.140:9092

"PLAINTEXT"表示協議,可選的值有PLAINTEXT和SSL,hostname可以指定IP地址,也可以用"0.0.0.0"表示對所有的網絡接口有效,如果hostname為空表示只對默認的網絡接口有效

也就是說如果你沒有配置advertised.listeners,就使用listeners的配置通告給消息的生產者和消費者,這個過程是在生產者和消費者獲取源數據(metadata)。如果都沒配置,那么就使用java.net.InetAddress.getCanonicalHostName()返回的值,對於ipv4,基本就是localhost了

然后你的生產者就會一直卡死,沒有反應,如果添加slf4j 橋接 log4j,將日志級別調到debug,發現如下的日志輸出

Updated cluster metadata version 2 to Cluster(nodes = [Node(0, 127.0.0.1, 9092)], partitions = [])
[cas-client-proxy] TRACE [main] org.apache.kafka.clients.producer.KafkaProducer.waitOnMetadata(374) | Requesting metadata update for topic topic_9527.

可以看到客戶端連接127.0.0.1:9092而不是你期望的服務器的地址!!!
如果按照0.8.x配置host.name和port屬性,會報如下問題

org.apache.kafka.clients.producer.KafkaProducer.send(348) | Exception occurred during message send:
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

本文地址:https://my.oschina.net/kyle1970/blog/2396318

原文地址:http://www.javacoder.cn/?p=849

解決方法為:

將

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

改為

advertised.listeners=PLAINTEXT://192.168.1.122:9092

192.168.1.122是kafka服務器的ip地址

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM