1.Producer connection to localhost:9092 unsuccessful java
遠程鏈接kafka發送消息成功的話是這樣: web
15-12-02 17:46:57,581 INFO kafka.producer.SyncProducer(?:?) ## Connected to 172.16.4.214:9092 for producing api
常常報錯以下: app
015-12-02 15:14:12 [ pool-1-thread-2:4217697 ] - [ ERROR ] Failed to collatemessages by topic, partition due to: fetching topic metadata for topics [Set(test)] from broker [ArrayBuffer(id:0,host:172.16.4.214,port:9092)] failed 2015-12-02 15:14:12 [ pool-1-thread-5:4217707 ] - [ ERROR ] Producer connection to 172.16.4.214:9092 unsuccessful java.net.ConnectException: Connection refused: connect at sun.nio.ch.Net.connect0(Native Method) at sun.nio.ch.Net.connect(Net.java:435) at sun.nio.ch.Net.connect(Net.java:427) at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:643) at kafka.network.BlockingChannel.connect(Unknown Source) at kafka.producer.SyncProducer.connect(Unknown Source) at kafka.producer.SyncProducer.getOrMakeConnection(Unknown Source) at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(Unknown Source) at kafka.producer.SyncProducer.send(Unknown Source) at kafka.client.ClientUtils$.fetchTopicMetadata(Unknown Source) at kafka.producer.BrokerPartitionInfo.updateInfo(Unknown Source) at kafka.producer.async.DefaultEventHandler$$anonfun$handle$2.apply$mcV$sp(Unknown Source) at kafka.utils.Utils$.swallow(Unknown Source) at kafka.utils.Logging$class.swallowError(Unknown Source) at kafka.utils.Utils$.swallowError(Unknown Source) at kafka.producer.async.DefaultEventHandler.handle(Unknown Source) at kafka.producer.Producer.send(Unknown Source) at kafka.javaapi.producer.Producer.send(Unknown Source) at com.hta.webmagic.pipeline.TestKafkaPipeline.KafkaProducer(TestKafkaPipeline.java:42) at com.hta.webmagic.pipeline.TestKafkaPipeline.process(TestKafkaPipeline.java:35) at us.codecraft.webmagic.Spider.processRequest(Spider.java:439) at us.codecraft.webmagic.Spider$1.run(Spider.java:336) at us.codecraft.webmagic.thread.CountableThreadPool$1.run(CountableThreadPool.java:74) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 2015-12-02 15:14:12 [ pool-1-thread-5:4217707 ] - [ ERROR ] fetching topic metadata for topics [Set(test)] from broker [ArrayBuffer(id:0,host:172.16.4.214,port:9092)] failed kafka.common.KafkaException: fetching topic metadata for topics [Set(test)] from broker [ArrayBuffer(id:0,host:172.16.4.214,port:9092)] failed at kafka.client.ClientUtils$.fetchTopicMetadata(Unknown Source) at kafka.producer.BrokerPartitionInfo.updateInfo(Unknown Source) at kafka.producer.async.DefaultEventHandler$$anonfun$handle$2.apply$mcV$sp(Unknown Source) at kafka.utils.Utils$.swallow(Unknown Source) at kafka.utils.Logging$class.swallowError(Unknown Source) at kafka.utils.Utils$.swallowError(Unknown Source) at kafka.producer.async.DefaultEventHandler.handle(Unknown Source) at kafka.producer.Producer.send(Unknown Source) at kafka.javaapi.producer.Producer.send(Unknown Source) at com.hta.webmagic.pipeline.TestKafkaPipeline.KafkaProducer(TestKafkaPipeline.java:42) at com.hta.webmagic.pipeline.TestKafkaPipeline.process(TestKafkaPipeline.java:35) at us.codecraft.webmagic.Spider.processRequest(Spider.java:439) at us.codecraft.webmagic.Spider$1.run(Spider.java:336) at us.codecraft.webmagic.thread.CountableThreadPool$1.run(CountableThreadPool.java:74) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.net.ConnectException: Connection refused: connect at sun.nio.ch.Net.connect0(Native Method) at sun.nio.ch.Net.connect(Net.java:435) at sun.nio.ch.Net.connect(Net.java:427) at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:643) at kafka.network.BlockingChannel.connect(Unknown Source) at kafka.producer.SyncProducer.connect(Unknown Source) at kafka.producer.SyncProducer.getOrMakeConnection(Unknown Source) at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(Unknown Source) at kafka.producer.SyncProducer.send(Unknown Source) ... 17 more問題分析: kafka 版本檢查 kafka_2.10-0.8.2.2 基本上就是server.xml 配置問題,保證hostname 和zookeer 的IP地址正確 版本:kafka_2.10-0.9.0.0 最後報錯最多是hosts 文件配置問題,須要配置好對應關係 這點和clouder 的集羣安裝相似 而後再檢查server.xml 配置文件 報錯表現: 本地命令行能夠正常的發送、接收消息,Eclipse 和遠程機器沒法發送消息。