【发布时间】:2016-08-23 09:18:48
【问题描述】:
我的 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());
}
我在catch (final ExecutionException executionException) {} 块中捕获了NotLeaderForPartitionException。
是否可以忽略此特定异常?
我的Kafka消息发送成功了吗?
【问题讨论】:
标签: exception-handling apache-kafka kafka-producer-api