java - 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,以便消息永远不会丢失吗?
解决方案
推荐阅读
- c++ - 在 C++ 中导入 dll 函数
- django - 我正在尝试在我的 django 项目中导入 gensim、pandas 和 numpy,但出现导入错误
- java - 如何修复 org.hibernate.MappingException 取消映射类
- php - Netbeans IDE 上的 PHP 7.3
- sql - SQL 聚合多个表中的数据并对指定列求和
- node.js - 如何将文本保存到语音音频文件客户端?
- bash - What is the best way to implement log rotation? (Node application)
- c++ - 是否可以动态地将函数分配给函数指针?
- angular - 当页面不活动时,RxJS 6 暂停或缓冲可观察
- javascript - How to get the value of a datepicker using framework7 and vuejs?