1、在使用Java API访问之前先在安装有kafka的各个节点启动服务
bin/kafka-server-start.sh config/server.properties &
2、报如下错误
props.put("metadata.broker.list", "storm1:9092,storm2:9092,storm3:9092"); props.put("serializer.class", "kafka.serializer.StringEncoder"); props.put("partitioner.class", "kafka.producer.DefaultPartitioner"); props.put("zookeeper.connect", "storm1:2181,storm2:2181,storm3:2181/kafka")
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)分析:报以上错误,我最初写的时候是写ip地址的,按理说如果写ip地址的话,是不需要在hosts文件里配置的,网上查了查,人家说需要配置hosts,所以配置了hosts之后就解决了。
原文地址:http://blog.csdn.net/panguoyuan/article/details/43605005