访问由 Source.actorRef 创建的 akka 流源的底层 ActorRef

编程入门 行业动态 更新时间:2024-10-12 14:18:14
本文介绍了访问由 Source.actorRef 创建的 akka 流源的底层 ActorRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 Source.actorRef 方法来创建一个 akka.stream.scaladsl.Source 对象.形式的东西

I'm trying to use the Source.actorRef method to create an akka.stream.scaladsl.Source object. Something of the form

import akka.stream.OverflowStrategy.fail import akka.stream.scaladsl.Source case class Weather(zip : String, temp : Double, raining : Boolean) val weatherSource = Source.actorRef[Weather](Int.MaxValue, fail) val sunnySource = weatherSource.filter(!_.raining) ...

我的问题是:如何将数据发送到基于 ActorRef 的源对象?

我认为向源发送消息是某种形式

I assumed sending messages to the Source was something of the form

//does not compile weatherSource ! Weather("90210", 72.0, false) weatherSource ! Weather("02139", 32.0, true)

但是 weatherSource 没有 ! 操作符或 tell 方法.

But weatherSource doesn't have a ! operator or tell method.

文档是没有过多描述如何使用 Source.actorRef,它只是说你可以......

The documentation isn't too descriptive on how to use Source.actorRef, it just says you can...

预先感谢您的评论和回复.

Thank you in advance for your review and response.

推荐答案

你需要一个Flow:

import akka.stream.OverflowStrategy.fail import akka.stream.scaladsl.Source import akka.stream.scaladsl.{Sink, Flow} case class Weather(zip : String, temp : Double, raining : Boolean) val weatherSource = Source.actorRef[Weather](Int.MaxValue, fail) val sunnySource = weatherSource.filter(!_.raining) val ref = Flow[Weather] .to(Sink.ignore) .runWith(sunnySource) ref ! Weather("02139", 32.0, true)

记住这都是实验性的,可能会改变!

Remember this is all experimental and may change!

更多推荐

访问由 Source.actorRef 创建的 akka 流源的底层 ActorRef

本文发布于:2023-11-25 02:30:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:底层   actorRef   Source   ActorRef   akka

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!