卡夫卡生产者回调异常 [英] Kafka producer callback Exception

查看:87
本文介绍了卡夫卡生产者回调异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们生成消息时,我们可以定义一个回调,该回调可能会发生异常:

When we produce messages we can define a callback, this callback can expect an exception:

kafkaProducer.send(producerRecord, new Callback() {
  public void onCompletion(RecordMetadata recordMetadata, Exception e) {
    if (e == null) {
      // OK
    } else {
      // NOT OK
    }
  }
});

考虑到生产者中的内置重试逻辑,我想知道开发者应该明确处理哪种异常?

Considered the buitl-in retry logic in the producer, I wonder which kind of exception should developers deal explicitly with?

推荐答案

根据

According to the Callback Java Docs there are the following Exception possible happening during callback:

在处理此记录期间引发的异常.如果未发生错误,则为Null.可能引发的异常包括:

The exception thrown during processing of this record. Null if no error occurred. Possible thrown exceptions include:

不可恢复的异常(致命,永远不会发送消息):

Non-Retriable exceptions (fatal, the message will never be sent):

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆