Apache kafka 与Akka和LogRotator一起提交卡夫卡

Apache kafka 与Akka和LogRotator一起提交卡夫卡,apache-kafka,akka-stream,Apache Kafka,Akka Stream,我正在尝试使用Consumer.committeablesource从带有Akka的Kafka读取数据。然后我想将数据写入共享文件夹中的文件中。 提交时,我们通常使用类似于的东西(Committer.flow(committerSettings) 但是,此方法不会返回Kafka流的值,因此之后我无法调用类似.runWith(LogRotatorSink.withSinkFactory(rotator,sink))的函数来写入数据。 以下是未提交的代码: Consumer.committableS

我正在尝试使用Consumer.committeablesource从带有Akka的Kafka读取数据。然后我想将数据写入共享文件夹中的文件中。 提交时,我们通常使用类似于
的东西(Committer.flow(committerSettings)

但是,此方法不会返回Kafka流的值,因此之后我无法调用类似
.runWith(LogRotatorSink.withSinkFactory(rotator,sink))
的函数来写入数据。 以下是未提交的代码:

Consumer.committableSource(settings, Subscriptions.topics(kafkaTopics.toSet))
  .via(processor)
  .prepend(headerCSVSource)
  .via(CsvFormatting.format(delimiter =
    CsvFormatting.SemiColon))
  .runWith(LogRotatorSink.withSinkFactory(rotator, sink))
以下是我认为我需要的:

 Consumer
        .committableSource(settings, Subscriptions.topics(kafkaTopics.toSet))
          .via(processor)
          .prepend(headerCSVSource)
          .via(CsvFormatting.format(delimiter =
            CsvFormatting.SemiColon))
          .via(Committer.flow(committerSettings))
          .runWith(LogRotatorSink.withSinkFactory(rotator, sink))
但是这不起作用,因为
via(Committer.flow)
不返回流值(但是flow[committeable,Done,NotUsed])

我需要的是仅在数据写入文件后提交偏移量。
如果您觉得其他选项(如使用plainSource/auto commit)更合适,我愿意考虑它们。

看起来您需要将流元素传递到一个接收器,并在成功时传递到另一个接收器

您可以在流中运行子流。大致如下:

.via(CsvFormatting.format(delimiter = CsvFormatting.SemiColon))
.mapAsync(1) { c =>
  Source.single(c).runWith(LogRotatorSink.withSinkFactory(rotator, sink)).map(_ => c)
}
.runWith(Committer.sink(committerSettings))

不过,经过深思熟虑,我认为最好不要使用sink来写入日志,而是使用其他不会终止流的方式。

感谢您的回答。我想知道,在您的解决方案中,写入文件失败时是否会提交偏移量?不,不会。那么您在
mapsync
中得到的是失败的未来,这是什么流失败。