首页 > 解决方案 > Kakfa 0.10.2.1 生产者关闭方法问题

问题描述

我们每次都在创建新的生产者连接,但在单独的线程中(40 个池,大部分时间将使用所有线程)并在完成工作时关闭它。它是一个java进程。

并非总是,但有时紧密连接需要超过 10 秒,并且观察到该特定消息从未发布过。

能否请你帮忙。

  Properties prop = new Properties();
  prop.put("bootstarp.servers",--);
  prop.put("acks","all");

  //some ssl properties
  ---
  //ends


    KafkaProducer connection = null;
    try { 
    connection = new KafkaProducer<String, byte[]>(props);
    msg.setTopic(topic);
    msg.setDate(new Date());
    connection.send(msg);
    } catch() {

    } finally {
    connection.close();// sometimes it takes more than 10 secs and the above message was not send
    }

生产者配置:

max.in.flight.requests.per.connection = 5

acks=全部

批量大小 = 16384

逗留.ms = 0

max.block.ms = 60000

request.timeout.ms = 5000

重试 = 0


更新 :

如果我在 connection.close() 之前调用 connection.flush() 会影响性能吗?

由于超时设置为 5000(request.timeout.ms),因此发送的生产者会失败,我可以将重试次数设置为 1,以便消息永远不会丢失吗?

标签: javaapache-kafkaapache-zookeeper

解决方案


推荐阅读