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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发环境解决 kafka Failed to send messages after 3 tries相关的知识,希望对你有一定的参考价值。

新建了一个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的参数如下:
技术分享

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

结果就可以了:

技术分享

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

技术分享

以上是关于开发环境解决 kafka Failed to send messages after 3 tries的主要内容,如果未能解决你的问题,请参考以下文章

service docker start 报错 :Failed to start docker.se

kafka启动报错:kafka.common.KafkaException: Failed to acquire lock on file .lock

Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar

SpringBoot中使用Kafka报错:Failed to construct kafka consumer

Failed to find data source: kafka

spring集成kafka运行时报错:Failed to construct kafka producer] with root cause