使用Source.actorPublisher和FlowGraph时,在akka-stream 1.0中获取actorRef

时间:2015-09-04 07:46:08

标签: akka-stream

我的问题涉及到:Accessing the underlying ActorRef of an akka stream Source created by Source.actorRef 有一些差异:

  1. 我正在使用akka-stream experimental 1.0
  2. 我正在使用actorPublisher模型
  3. 我正在使用FlowGraph dsl进行并行处理的流定义
  4. 我找不到让actorRef将消息发送到Source持有的Actor Publisher实例的方法。

     def run(implicit system: ActorSystem) = {
       import system.dispatcher
       implicit val materializer = ActorMaterializer()
    
       val source = Source.actorPublisher[TestRequest](TestActor.props).map { request => request.event }
    
       //Implementation in subpackage
       val sinkLevel1 = Sinks.sinkLevel1 
       val sinkLevel2 = Sinks.sinkLevel2
    
       //Implementation in subpackage
       val stageTriage = FlowStages.stageTriage    
       val stageEvalProcess1 = FlowStages.stageEvalProcess1
       val stageEvalProcess2 = FlowStages.stageEvalProcess2
    
       val pipeline = FlowGraph.closed(){ implicit builder => 
         import FlowGraph.Implicits._
    
         val stageDispatchByRuleLevels = builder.add(Broadcast[TriagedSystemEvent](2))
    
         source ~> stageTriage ~> stageDispatchByRuleLevels
                                  stageDispatchByRuleLevels ~> stageEvalProcess1 ~> sinkLevel1
                                  stageDispatchByRuleLevels ~> stageEvalProcess2 ~> sinkLevel2
    
       }
    
       pipeline.run()
    
     }
    

    感谢您的帮助!

    奥利弗

1 个答案:

答案 0 :(得分:1)

根据诺亚在链接问题中的回答,如果你添加

val ref = pipeline.run()

然后您可以向ref发送消息,例如

ref ! ...