Reactive Kafka不打印消息

时间:2016-04-25 22:07:09

标签: apache-kafka reactive-programming akka-stream

我想了解为什么下面的代码会实际打印

val consumerProperties = ConsumerProperties(
  bootstrapServers = "localhost:9092",
  topic = "test",
  groupId = "group",
  valueDeserializer = new StringDeserializer
).commitInterval(1200 milliseconds)

consumerWithOffSetSink = kafka.consumeWithOffsetSink(consumerProperties)
Source.fromPublisher(consumerWithOffSetSink.publisher)
    .map{ msg =>
      println(msg.value())
      msg
    }
  .to(consumerWithOffSetSink.offsetCommitSink).run()

然而,下面的代码并没有做我期望它做的事情:

val consumerProperties = ConsumerProperties(
  bootstrapServers = "localhost:9092",
  topic = "test",
  groupId = "group",
  valueDeserializer = new StringDeserializer
).commitInterval(1200 milliseconds)

consumerWithOffSetSink = kafka.consumeWithOffsetSink(consumerProperties)
Source.fromPublisher(consumerWithOffSetSink.publisher)
  .runForeach(msg => println(msg.value()))
  .foreach(msg => println(msg))

我想要了解的是如何构建我的应用程序以进行流式传输,我仍然处理整体Akka Streams以及它们如何在内部工作的过程。

0 个答案:

没有答案