[英]Kafka Producer Request Timeout setting
I would like to set request time-out so added request.timeout.ms parameter. 我想设置请求超时,所以添加了request.timeout.ms参数。 Bu when I have broken instinctively the broker connection there is not any timeout error occur?
当我本能地断开代理连接时,没有发生任何超时错误?
What I am missing in this configuration? 我在这个配置中缺少什么? Do I need to modify server setting as well?
我是否还需要修改服务器设置?
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 version : kafka_2.11-0.10.2.0 卡夫卡版 :kafka_2.11-0.10.2.0
pom.xml 的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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.