kafka Failed to send messages after 3 tries 问题解决
kafka Failed to send messages after 3 tries.
?
在kafka0.8開發(fā)過程中 生產(chǎn)者測試用例碰到了
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)
這樣的錯誤。
起初以為是網(wǎng)絡(luò)問題,經(jīng)確認(rèn)網(wǎng)絡(luò)沒有問題。
?
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();
這是生產(chǎn)者的代碼 在向服務(wù)器發(fā)起連接后,在kafka的服務(wù)器配置中有zookeeper.connect=xx.xx.xx.xx:2181的配置 這時候kafka會查找zookeeper
?
那么如果我們的hosts 中沒有做hosts的配置 kafka經(jīng)多次嘗試連接不上就會報上面的錯誤。
?
解決辦法:配置hosts文件 做zookeeper服務(wù)器的映射配置。
?
出現(xiàn)此種錯誤 還有一種情況
# 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
遠(yuǎn)程連接的話 是根據(jù)這個配置來找broker的,默認(rèn)是localhost ,所以如果不是本機(jī)運(yùn)行的話 應(yīng)該設(shè)置此值 來確保通信暢通。
轉(zhuǎn)載于:https://www.cnblogs.com/405845829qq/p/5733210.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的kafka Failed to send messages after 3 tries 问题解决的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 经典的大牛博客推荐
- 下一篇: 【bzoj2806】 Ctsc2012—