zoukankan      html  css  js  c++  java
  • kafka Failed to send messages after 3 tries 问题解决

    kafka Failed to send messages after 3 tries.

    在kafka0.8开发过程中 生产者测试用例碰到了

    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)
    at com.tuan55.kafka.test.TestP.main(TestP.java:20)

    这样的错误。

    起初以为是网络问题,经确认网络没有问题。

    Properties props = new Properties();
    props.put("metadata.broker.list", "xx.xx.xx.xx:9092");
    props.put("serializer.class", "kafka.serializer.StringEncoder");
    props.put("request.required.acks", "1");
    ProducerConfig config = new ProducerConfig(props);
    Producer<String, String> producer = new Producer<String, String>(config);
    KeyedMessage<String, String> km = new KeyedMessage<String, String>("mm", "key-1", "content-1-中文");
    producer.send(km);


    producer.close();

    这是生产者的代码 在向服务器发起连接后,在kafka的服务器配置中有zookeeper.connect=xx.xx.xx.xx:2181的配置 这时候kafka会查找zookeeper

    那么如果我们的hosts 中没有做hosts的配置 kafka经多次尝试连接不上就会报上面的错误。

    解决办法:配置hosts文件 做zookeeper服务器的映射配置。

    出现此种错误 还有一种情况

    # Hostname the broker will advertise to producers and consumers. If not set, it uses the
    # value for "host.name" if configured.  Otherwise, it will use the value returned from
    # java.net.InetAddress.getCanonicalHostName().
    advertised.host.name=192.168.1.118

    远程连接的话 是根据这个配置来找broker的,默认是localhost ,所以如果不是本机运行的话 应该设置此值 来确保通信畅通。

  • 相关阅读:
    Animation Curve运动曲线
    Unity3D Collider类的信息传输Ontrigger*与OnCollision*
    springmvc拦截器的简单了解
    JDK中的注解简单了解
    面试加分项---HashMap底层实现原理
    springmvc参数绑定
    springmvc和struts2的区别
    修改tomcat的编码方式,可以解决某些get请求乱码问题
    springmvc 怎么响应json数据
    权限控制框架---shiro入门
  • 原文地址:https://www.cnblogs.com/405845829qq/p/5733210.html
Copyright © 2011-2022 走看看