Akka Kafka Producer中的错误处理

时间:2016-07-22 23:47:32

标签: akka-stream akka-kafka

我正在使用reactive-kafka-core 0.10.1(针对Kafka 0.9.x)。看起来Kafka生产者actor在回调函数遇到错误时就会停止。有没有办法自定义这种行为?我们的用例是尝试恢复和重新发送消息。

private def processElement(element: ProducerMessage[K, V]) = {
  val record = richProducer.props.partitionizer(element.value) match {
  case Some(partitionId) => new ProducerRecord(richProducer.props.topic, partitionId, element.key, element.value)
  case None => new ProducerRecord(richProducer.props.topic, element.key, element.value)
}
richProducer.producer.send(record, new Callback {
  override def onCompletion(metadata: RecordMetadata, exception: Exception) = {
    if (exception != null) {
      handleError(exception)
    }
  }
})
()} private def handleError(ex: Throwable) = {
log.error(ex, "Stopping Kafka subscriber due to fatal error.")
stop()

}

0 个答案:

没有答案