Fork me on GitHub
听雨轩
生命易破碎,梦想只争朝夕!

新建了一个kafka集群,在window下写了一个简单的producer做测试,结果遇到了消息发送失败的问题,代码如下:

        Properties props = new Properties();
        props.put("metadata.broker.list", "192.168.1.107:6667");
        props.put("serializer.class", "kafka.serializer.StringEncoder");
//        props.put("partitioner.class", "example.producer.SimplePartitioner");
        props.put("request.required.acks", "1");

        ProducerConfig config = new ProducerConfig(props);
        Producer producer = new Producer<String, String>(config);
        String payload = String.format("ayuananybc%s", "test");
        KeyedMessage<String, String> data = new KeyedMessage<String, String>("mytopic", payload);
        producer.send(data);
 
 
经过查看kafka broker的参数如下:
image

于是猜测是不是本地运行的时候不认识Slave1(192.168.1.107)? 然后我在hosts中加上:192.168.1.107  Slave1。

结果就可以了:

image

其实原因是让kafka知道zookeeper的监听地址,我们不修改hosts,加上如下配置也是可以的:

image

posted on 2016-01-30 23:33  流水殇  阅读(6079)  评论(0编辑  收藏  举报