简体   繁体   English

当经纪人关闭时,kafka生产者不会抛出异常

[英]kafka producer does not throw exception when broker is down

Created a cluster with two brokers using same zookeeper and trying to produce message to a topic whose details are as below.使用相同的 zookeeper 创建了一个包含两个代理的集群,并尝试向一个主题生成消息,其详细信息如下。

kafka 主题描述

When the producer sets acks="all" or -1, min.insync.replicas="2" , it is supposed to receive acknowledgement from the brokers(leaders and replicas) but when one broker is shut manually while it is producing, it is making no difference to the kafka producer even when acks="all" can someone explain the reason for this weird behavior?当生产者设置acks="all"或 -1, min.insync.replicas="2"时,它应该从代理(领导者和副本)接收确认,但是当一个代理在生产时手动关闭时,它即使 acks="all" 有人可以解释这种奇怪行为的原因,对 kafka 制作人也没有影响?

brokers are on 9091,9092.经纪人在 9091,9092。

acks = -1
batch.size = 16384
bootstrap.servers = [localhost:9092]
buffer.memory = 33554432
client.dns.lookup = use_all_dns_ips
client.id = producer-1
compression.type = none
connections.max.idle.ms = 540000
delivery.timeout.ms = 120000
enable.idempotence = false
interceptor.classes = []
internal.auto.downgrade.txn.commit = false
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
linger.ms = 0
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.max.age.ms = 300000
metadata.max.idle.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 2147483647
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.2
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
transaction.timeout.ms = 60000
transactional.id = null
value.serializer = class org.apache.kafka.common.serialization.StringSerializer

Below is the source code for the kafka producer下面是kafka生产者的源代码

public static  void main(String k[]) {
    Properties prop=new Properties();
    prop.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"localhost:9092");
    prop.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    prop.setProperty(ProducerConfig.ACKS_CONFIG,"all");
    prop.setProperty("min.insync.replicas", "2");
    prop.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    KafkaProducer<String,String> producer=new KafkaProducer<>(prop);
    ProducerRecord<String,String> rec=new ProducerRecord<String,String>("clust_topic","123");
while(true) {
    producer.send(rec, new Callback() {

        @Override
        public void onCompletion(RecordMetadata rm, Exception arg1) {
            System.out.println(arg1);
            if(arg1!=null)
              System.out.println(arg1);
            else
                System.out.println(rm.topic()+" "+rm.partition()+" "+rm.offset()+" ");      
        }       
    });
  }
}

kafkacallback 的 Eclipse 控制台输出

ack=all means that it requires ack from all in-sync replicas, not from all replicas (refer to documentation ) ack=all意味着它需要来自所有同步副本的确认,而不是来自所有副本(请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM