Accessing the underlying ActorRef of an akka stream Source created by Source.actorRef

前端 未结 3 1968
情歌与酒
情歌与酒 2020-11-30 06:04

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


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 06:34

    You need a 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!

提交回复
热议问题