新建了一个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的参数如下:
开发环境解决 kafka Failed to send messages after 3 tries

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

结果就可以了:

开发环境解决 kafka Failed to send messages after 3 tries

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

开发环境解决 kafka Failed to send messages after 3 tries

相关文章:

  • 2022-12-23
  • 2021-12-17
  • 2021-11-26
  • 2021-09-04
  • 2021-07-30
  • 2022-01-06
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案