简体   繁体   English

在Akka-http中使用handleWebsocketMessage

[英]using handleWebsocketMessage in akka-http

Using akka-http, how can I construct a Flow[Message, Message, _] to pass to handleWebsocketMessage that only listens to incoming data but does not write anything back? 使用akka-http,如何构造Flow[Message, Message, _]传递给handleWebsocketMessage ,该方法仅侦听传入的数据但不回写任何内容? Is it possible to use a Sink in anyway? 反正可以使用水槽吗? Because a Sink sounds like what I need. 因为水槽听起来像我所需要的。

It's possible to create a Flow from independent Source and Sink , which is what you'll need here. 可以从独立的SourceSink创建Flow ,这是您在这里需要的。 To get more inside info about how it can word you may want to read the stream composition docs. 要获取有关如何发音的更多内部信息,您可能需要阅读流组成文档。

In general what you need is to create a Flow such that it is a Sink that can handle the incoming messages and a Source that never emits, this is achieved by: 通常,您需要创建一个Flow,使其成为可以处理传入消息的Sink和永不发出的Source,这可以通过以下方法实现:

Flow.wrap(Sink.foreach(println), Source.lazyEmpty)(Keep.none)

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

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