gpt4 book ai didi

exception-handling - 我可以忽略org.apache.kafka.common.errors.NotLeaderForPartitionExceptions吗?

转载 作者:行者123 更新时间:2023-12-04 05:47:11 27 4
gpt4 key购买 nike

我的Apache Kafka生产者(0.9.0.1)间歇性地抛出一个

org.apache.kafka.common.errors.NotLeaderForPartitionException

我执行Kafka发送的代码与此类似

final Future<RecordMetadata> futureRecordMetadata = KAFKA_PRODUCER.send(new ProducerRecord<String, String>(kafkaTopic, UUID.randomUUID().toString(), jsonMessage));

try {
futureRecordMetadata.get();
} catch (final InterruptedException interruptedException) {
interruptedException.printStackTrace();
throw new RuntimeException("sendKafkaMessage(): Failed due to InterruptedException(): " + sourceTableName + " " + interruptedException.getMessage());
} catch (final ExecutionException executionException) {
executionException.printStackTrace();
throw new RuntimeException("sendKafkaMessage(): Failed due to ExecutionException(): " + sourceTableName + " " + executionException.getMessage());
}

我在 NotLeaderForPartitionException块中捕获了 catch (final ExecutionException executionException) {}

是否可以忽略此特定异常?

我的Kafka讯息发送成功了吗?

最佳答案

如果您收到NotLeaderForPartitionException,则您的数据是而不是写入成功。

每个主题分区由一个或多个代理(具有一个领导者;其余的代理称为跟随者)存储,具体取决于您的复制因子。生产者需要向领导者经纪人发送新消息(向跟随者的数据复制在内部进行)。

您的生产者客户端未连接到正确的代理,即未连接到领导者的关注者(或不再是关注者的经纪人),并且该代理拒绝了您的发送请求。如果领导者发生了变化,但生产者仍然具有过时的缓存元数据,关于哪个代理是分区的领导者,则可能发生这种情况。

关于exception-handling - 我可以忽略org.apache.kafka.common.errors.NotLeaderForPartitionExceptions吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36917553/

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