测试kafka ha并获取,networkexception:服务器在收到响应之前断开连接

huwehgph  于 2021-06-06  发布在  Kafka
关注(0)|答案(2)|浏览(495)

运行融合Kafka4.1.1社区。
我有。。。
最小同步副本数=2
主题:1分区,副本计数3
总共3个经纪人。
producer设置为acks=-1
所有其他生产者设置都是默认设置。
我启动了我的应用程序,当它开始给Kafka写记录的时候,我故意找了一个经纪人,我立刻得到: org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received. 基于上述设置。producer write()是否应该成功执行此操作而不抛出错误?
澄清
我故意杀了一个经纪人
这似乎只发生在领导者经纪人被杀的情况下?

oaxa6hgo

oaxa6hgo1#

没有看到完整配置。还有日志信息,很难说,还是。。
在Kafka,所有的写作都要经过领导人分区。在你的背景下,三个经纪人中,你杀了一个。因此,应该可以成功地写入剩下的2个并获得确认。但是,如果被杀死的代理是leader节点,则可能会导致异常。
从文档中:
acks=所有这一切意味着领导者将等待全套同步副本确认记录。这保证了只要至少有一个同步副本保持活动状态,记录就不会丢失。这是最有力的保证。
在任何情况下,您都可以将retries设置为大于0的值,并查看其行为-应该选出一个新的领导人,并且您的写入最终应该成功

rkue9o1l

rkue9o1l2#

用于kafka binder for azure eventhub for kafka的spring云流
例外情况:

{"timestamp":"2020-09-23 23:37:18.541","level":"ERROR","class":"org.springframework.kafka.support.LoggingProducerListener.onError 84", "thread":"kafka-producer-network-thread | producer-2","traceId":"","message":Exception thrown when sending a message with key='null' and payload='{123, 34, 115, 116, 97, 116, 117, 115, 34, 58, 34, 114, 101, 97, 100, 121, 34, 44, 34, 101, 118, 101...' to topic executor-networkexception and partition 3:}
org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received.

{"timestamp":"2020-09-23 23:37:18.545","level":"WARN ","class":"org.apache.kafka.clients.producer.internals.Sender.completeBatch 568", "thread":"kafka-producer-network-thread | producer-2","traceId":"","message":[Producer clientId=producer-2] Received invalid metadata error in produce request on partition executor-networkexception-3 due to org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received.. Going to request metadata update now}

解决方案:设置空闲时间、重试计数、重试退避时间-

spring:
  cloud:
    stream:
      kafka:
        binder:
          brokers: srsmvsdneventhubstage.servicebus.windows.net:9093
          configuration:
            sasl.jaas.config: 'org.apache.kafka.common.security.plain.PlainLoginModulerequiredusername="$ConnectionString"password="Endpoint=sb://xxxxx.servicebus.windows.net/;=";'
            sasl.mechanism: PLAIN
            security.protocol: SASL_SSL
            retries: 3
            retry.backoff.ms: 60
            connections.max.idle.ms: 240000

参考文献:
http://kafka.apache.org/090/documentation.html (readhttp://kafka.apache.org/090/documentation.html#producerconfigs)

[https://github.com/Azure/azure-event-hubs-for-kafka/blob/master/CONFIGURATION.md][2]  (read connections.max.idle.ms)

日志:

"org.apache.kafka.clients.producer.ProducerConfig.logAll 279", "thread":"hz._hzInstance_1_dev.cached.thread-14","traceId":"","message":ProducerConfig values: 
        acks = 1
        batch.size = 16384
        bootstrap.servers = [srsmvsdneventhubstage.servicebus.windows.net:9093]
        buffer.memory = 33554432
        client.id = 
        compression.type = none
        connections.max.idle.ms = 540000
        enable.idempotence = false
        interceptor.classes = []
        key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
        linger.ms = 0
        max.block.ms = 60000
        max.in.flight.requests.per.connection = 5
        max.request.size = 1048576
        metadata.max.age.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 = 0
        retry.backoff.ms = 100
        sasl.client.callback.handler.class = null
        sasl.jaas.config = [hidden]
        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 = PLAIN
        security.protocol = SASL_SSL
        send.buffer.bytes = 131072
        ssl.cipher.suites = null
        ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
        ssl.endpoint.identification.algorithm = https
        ssl.key.password = null
        ssl.keymanager.algorithm = SunX509
        ssl.keystore.location = null
        ssl.keystore.password = null
        ssl.keystore.type = JKS
        ssl.protocol = TLS
        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.ByteArraySerializer
    }

新建-

"org.apache.kafka.clients.producer.ProducerConfig.logAll 279", "thread":"hz._hzInstance_1_dev.cached.thread-20","traceId":"","message":ProducerConfig values: 
            acks = 1
            batch.size = 16384
            bootstrap.servers = [xxxxx.servicebus.windows.net:9093]
            buffer.memory = 33554432
            client.id = 
            compression.type = none
          **connections.max.idle.ms = 240000**
            enable.idempotence = false
            interceptor.classes = []
            key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
            linger.ms = 0
            max.block.ms = 60000
            max.in.flight.requests.per.connection = 5
            max.request.size = 1048576
            metadata.max.age.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 = 3**
          **retry.backoff.ms = 60**
            sasl.client.callback.handler.class = null
            sasl.jaas.config = [hidden]
            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 = PLAIN
            security.protocol = SASL_SSL
            send.buffer.bytes = 131072
            ssl.cipher.suites = null
            ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
            ssl.endpoint.identification.algorithm = https
            ssl.key.password = null
            ssl.keymanager.algorithm = SunX509
            ssl.keystore.location = null
            ssl.keystore.password = null
            ssl.keystore.type = JKS
            ssl.protocol = TLS
            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.ByteArraySerializer
        }

相关问题