代码之家  ›  专栏  ›  技术社区  ›  Arne Claassen

将akka流源多路复用为两个副本

  •  1
  • Arne Claassen  · 技术社区  · 6 年前

    我试图将流媒体源缓存到磁盘,同时也将其作为一个文件发送出去 HttpResponse Source[ByteString,_] 我想交给你 HttpEntity ,但我还希望将相同的数据运行到 FileIO.toPath 下沉。

                           |-> FileIO.toPath
    Source[ByteString,_] ->|
                           |-> HttpEntity(contentType, Source[ByteString,_]
    

    Broadcast FileIO.toPath 这是一个水槽, 期待 Source

    Source.fromGraph 这看起来像是从GraphStage创建一个源,例如 广播 舞台,但我不太明白我该如何获得 FileIO 沉入其中。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Jeffrey Chung    6 年前

    你可以用 alsoTo :

    val originalSource: Source[ByteString, _] = ???
    val cachedSource: Source[ByteString, _] = originalSource.alsoTo(FileIO.toPath(/*...*/))
    val entity = HttpEntity(contentType, cachedSource)