Akka RestartSink不会重新启动流

时间:2018-12-13 01:33:27

标签: scala akka actor akka-stream

我这里有一个简单的akka​​流,无法弄清为什么在killSwitches中止处理后,该流从不正确地重新启动。任何指针将不胜感激

object TestMain extends App {
    implicit val actorSystem = ActorSystem("TestMain")
    implicit val materializer = ActorMaterializer()
    val sharedKillSwitch = KillSwitches.shared("fp-change-kill-switch")

    // This stream keeps restarting after aborting and stops after 10 times 
    RestartSource.withBackoff(1 second, 1 second, 0.2, 10) {
        () => Source.tick(1 second, 1 second, 200).via(sharedKillSwitch.flow)
    }.to(Sink.foreach(println((_)))).run()

   // This does not restart at all
   Source.tick(1 second, 1 second, 400)
    .via(sharedKillSwitch.flow)
    .to(RestartSink.withBackoff[Int](1 second, 1 second, 0.2, 10) {
      () => Sink.foreach(println(_))
    }).run()

  Thread.sleep(5000)
  sharedKillSwitch.abort(new Exception(""))

}

我需要的是不重新启动整个流(包括源),而仅重新启动接收器-就像情况2中那样,仅使用RestartSink

1 个答案:

答案 0 :(得分:0)

RestartSink和RestartSource有区别。

RestartSource在连接的流或接收器发出错误或提示时重新启动。

RestartSink仅检查其管理的接收器的取消。我认为您应该能够将KillSwitch流集成到应该在重新启动时重新创建的接收器中。

查看此documentation