2

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?

gravetii
  • 9,273
  • 9
  • 56
  • 75
  • 1
    You can flatMap over the Future returned by using the `watchTermination` operator. https://doc.akka.io/docs/akka/current/stream/operators/Source-or-Flow/watchTermination.html – Sean Glover Oct 29 '20 at 19:40
  • 1
    Check this post: https://stackoverflow.com/questions/12436397/how-to-wait-for-akka-actor-system-to-terminate#:~:text=terminate%20is%20still%20the%20way%20to%20terminate%20the%20system.&text=As%20of%20Akka%202.4%2C%20you,system%2C%20you%20should%20use%20ActorSystem – Explorer Nov 01 '20 at 16:56

1 Answers1

0

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.

Igmar Palsenberg
  • 637
  • 4
  • 10