本文介绍了访问由Source.actorRef创建的akka​​流Source的基础ActorRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用方法来创建对象。格式如下

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

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

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...

在此先感谢您的评论和答复。 p>

Thank you in advance for your review and response.

推荐答案

您需要流程

  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​​流Source的基础ActorRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:37