从Lagom / Akka Kafka的Websocket主题订户创建源

时间:2018-09-12 22:59:58

标签: scala websocket apache-kafka akka-stream lagom

我希望我的Lagom仅限订阅者服务订阅Kafka主题,并将消息流式传输到Websocket。我使用此文档(https://www.lagomframework.com/documentation/1.4.x/scala/MessageBrokerApi.html#Subscribe-to-a-topic)作为准则,定义了以下服务:

    // service call
    def stream(): ServiceCall[Source[String, NotUsed], Source[String, NotUsed]]

    // service implementation
    override def stream() = ServiceCall { req =>
      req.runForeach(str => log.info(s"client: %str"))
      kafkaTopic().subscribe.atLeastOnce(Flow.fromFunction(
        // add message to a Source and return Done
      ))
      Future.successful(//some Source[String, NotUsed])

但是,我不太清楚如何处理我的kafka消息。 Flow.fromFunction返回[String, Done, _],这意味着我需要将这些消息(字符串)添加到在订户外部创建的Source中。

所以我的问题是双重的: 1)如何创建一个akka流源,以便在运行时从kafka主题订阅者那里接收消息? 2)在Flow中如何将kafka消息附加到所述源?

0 个答案:

没有答案