How to allow/wait for Akka streams to complete on JVM shutdown?

Viewed 349

Basically, my goal is that when I restart the server where a bunch of Akka streams are being processed, the shutdown hook should wait for all the streams to complete before terminating the ActorSystem.

I have a close method defined which terminates the actor system, like this -

def close(): Future[Terminated] = {
    logger.info("Terminating actor system")
    system.terminate()
  }

and I call this from my JVM's shutdown hook.

However, this apparently doesn't wait for the streams to complete, but instead, just aborts the running streams and terminates the actors, which doesn't solve what I'm trying to do. So, this doesn't seem right.

Also, I read through the documentation that actors support their own shutdown hooks, but how do I configure them such that the streams run until completion, and only then allow the JVM to exit?

1 Answers

We use a killswitch for that : That allows shutting down the actor stream. You still need to wait until all streams complete, the killswitch just initiates the proper stream shutdown.

Related