简体   繁体   English

Akka-streams TCP - 使用不同的接收器

[英]Akka-streams TCP - consume with different Sinks

How can I switch Sink connected by tcp.bind() to TCP Source?如何将通过tcp.bind()连接的 Sink 切换到 TCP Source? For example, lets say i have:例如,假设我有:

   Sink<ByteString, CompletionStage<Void>> tmpFileSink = FileIO
            .toPath(destination)
            .mapMaterializedValue(this::noticeCompletion);

    tcp
       .bind(host, port)
       .to(Sink.foreach(incomingConnection -> wire(incomingConnection, tmpFileSink)))
       .run(materializer);

For now, it saves incoming bytes to destination file.目前,它将传入字节保存到destination文件。 I would like to change, the destination file dynamically.我想动态更改目标文件。 How can I achieve that using akka-streams?如何使用 akka-streams 实现这一目标?

Have a look at PartitionHub documentation here .此处查看PartitionHub文档。 This allows you to dynamically switch the elements to different destinations.这允许您动态地将元素切换到不同的目的地。

In your question you didn't specify how exactly you need to make the decision about where each element should go.在您的问题中,您没有具体说明您需要如何决定每个元素应该在 go 的位置。 If the PartitionHub can't cut it you may need to go lower level and implement a custom processing stage.如果PartitionHub无法切割它,您可能需要 go 更低级别并实现自定义处理阶段。 You can see how to do that here你可以在这里看到如何做到这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM