4

我正在使用 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()

}

4

0 回答 0