加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 09:40:57 所属栏目:安全 来源:网络整理
导读:我试图使用 Source.actorRef方法创建一个 akka.stream.scaladsl.Source对象。一些形式的东西 import akka.stream.OverflowStrategy.failimport akka.stream.scaladsl.Sourcecase class Weather(zip : String,temp : Double,raining : Boolean)val weatherSou
我试图使用 Source.actorRef方法创建一个 akka.stream.scaladsl.Source对象。一些形式的东西

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的Source对象?

我假设发送消息到源是一些形式

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

但weatherSource没有!运算符或告诉方法。

documentation对于如何使用Source.actorRef来说不是太描述性,它只是说你可以…

提前感谢您的回顾和回复。

解决方法

你需要一个流程:

import akka.stream.OverflowStrategy.fail
  import akka.stream.scaladsl.Source
  import akka.stream.scaladsl.{Sink,Flow}

  case class Weather(zip : String,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",true)

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读