日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kafka Failed to send messages after 3 tries 问题解决

發布時間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kafka Failed to send messages after 3 tries 问题解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kafka Failed to send messages after 3 tries.

?

在kafka0.8開發過程中 生產者測試用例碰到了

Exception in thread "main" kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.
at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:90)
at kafka.producer.Producer.send(Producer.scala:76)
at kafka.javaapi.producer.Producer.send(Producer.scala:33)
at com.tuan55.kafka.test.TestP.main(TestP.java:20)

這樣的錯誤。

起初以為是網絡問題,經確認網絡沒有問題。

?

Properties props = new Properties();
props.put("metadata.broker.list", "xx.xx.xx.xx:9092");
props.put("serializer.class", "kafka.serializer.StringEncoder");
props.put("request.required.acks", "1");
ProducerConfig config = new ProducerConfig(props);
Producer<String, String> producer = new Producer<String, String>(config);
KeyedMessage<String, String> km = new KeyedMessage<String, String>("mm", "key-1", "content-1-中文");
producer.send(km);


producer.close();

這是生產者的代碼 在向服務器發起連接后,在kafka的服務器配置中有zookeeper.connect=xx.xx.xx.xx:2181的配置 這時候kafka會查找zookeeper

?

那么如果我們的hosts 中沒有做hosts的配置 kafka經多次嘗試連接不上就會報上面的錯誤。

?

解決辦法:配置hosts文件 做zookeeper服務器的映射配置。

?

出現此種錯誤 還有一種情況

# Hostname the broker will advertise to producers and consumers. If not set, it uses the
# value for "host.name" if configured. ?Otherwise, it will use the value returned from
# java.net.InetAddress.getCanonicalHostName().
advertised.host.name=192.168.1.118

遠程連接的話 是根據這個配置來找broker的,默認是localhost ,所以如果不是本機運行的話 應該設置此值 來確保通信暢通。

轉載于:https://www.cnblogs.com/405845829qq/p/5733210.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的kafka Failed to send messages after 3 tries 问题解决的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。