gpt4 book ai didi

java - Kafka Producer请求超时设置

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:10:41 26 4
gpt4 key购买 nike

我想设置请求超时,所以添加了 request.timeout.ms 参数。但是,当我本能地断开代理连接时,没有发生任何超时错误吗?

我在此配置中缺少什么?我是否也需要修改服务器设置?

 public void init() {
LOGGER.info("initializing KafkaProducer: Topic Name: {}", topic);
System.out.println("initializing KafkaProducer: Topic Name: {}");
Properties properties = new Properties();
properties.put("bootstrap.servers", brokerList);
properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("acks", "1");
properties.put("retries", "3");
properties.put("linger.ms", 5);
properties.put("block.on.buffer.full", false);
properties.put("request.timeout.ms", "1000");
//properties.put("metadata.fetch.timeout.ms", 1000);



producer = new KafkaProducer<>(properties);
}


public void produce(String txnLogStr) {
ProducerRecord<String, String> record = new ProducerRecord<String, String>(topic, txnLogStr);
producer.send(record, new ProducerCallback());

}

private class ProducerCallback implements Callback {
@Override
public void onCompletion(RecordMetadata recordMetadata, Exception e) {
System.out.println("onCompletion recordMetadata:"+recordMetadata.offset()+", e:"+e);
if (e != null && recordMetadata != null) {
LOGGER.error("Kafka Queue problem. Topic: {}", topic, e);
e.printStackTrace();
}else {
System.out.println("No error");
}
}
}

卡夫卡版本:kafka_2.11-0.10.2.0

pom.xml

 <dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>0.10.2.0</version>

</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.10.2.0</version>

</dependency>


</dependencies>

最佳答案

使用以下属性设置

properties.put("metadata.fetch.timeout.ms", "1000");

关于java - Kafka Producer请求超时设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45751457/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com