scala – 从EventStream创建源代码
发布时间:2020-12-16 18:17:23 所属栏目:安全 来源:网络整理
导读:我正在使用PlayFramework 2.5.3,并希望从akka.event.EventStream创建一个akka.stream. scaladsl.Source(事件流是actor系统的一部分).事件流将产生来自某种类型的事件,因此我需要订阅该特定类型的事件并使用play.api.mvc.Results.chunked来推送它们.有没有简
我正在使用PlayFramework 2.5.3,并希望从akka.event.EventStream创建一个akka.stream.
scaladsl.Source(事件流是actor系统的一部分).事件流将产生来自某种类型的事件,因此我需要订阅该特定类型的事件并使用play.api.mvc.Results.chunked来推送它们.有没有简单的方法使用Akka Streams 2.4.5创建这样的Source?
解决方法
您可以将
Source.actorRef 与订阅一起使用. Source.actorRef是一个实现ActorRef的源,所以你可以这样做:
// choose the buffer size of the actor source and how the actor // will react to its overflow val eventListenerSource = Source.actorRef[YourEventType](32,OverflowStrategy.dropHead) // run the stream and obtain all materialized values val (eventListener,...) = eventListenerSource .viaMat(...)(Keep.left) <...> .run() // subscribe the source actor to the stream actorSystem.eventStream.subscribe(eventListener,classOf[YourEventType]) // now events emitted by the source will go to the actor // and through it to the stream 请注意,actorRef源有些限制,例如,它自然不支持其内部缓冲区的背压溢出策略.您可能希望将 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |