如何优雅地停止必须部署的 akka-http 服务器的 actor 系统. [英] How to stop gracefully the actor system for an akka-http server that must be deployed.

查看:24
本文介绍了如何优雅地停止必须部署的 akka-http 服务器的 actor 系统.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚用 akka-http 创建了我的第一个休息服务器.问题是我不知道如何以一种可以优雅地关闭 actor 系统的方式部署服务器.

I just created my first rest server with akka-http. The problem is that I do not know how to deploy the server in such a way that I could gracefully shutdown the actor system.

例如,我在这里找到了一些东西:https://stackoverflow.com/a/17399574/5388513 你可以在哪里使用 Akka 的微内核,但它已被弃用.我尝试使用 sbt-native-package,但我不知道如何优雅地关闭 actor 系统.

For example I found something here: https://stackoverflow.com/a/17399574/5388513 where you could use Akka's microkernel, but it is deprecated. I tried using sbt-native-package, but I do not know how to gracefully shutdown the actor system.

谢谢!

推荐答案

可以添加关机钩子:

// import scala.concurrent.duration._
//shutdown Hook
scala.sys.addShutdownHook {
  logger.info("Terminating...")
  actorSystem.terminate()
  Await.result(actorSystem.whenTerminated, 30 seconds)
  logger.info("Terminated... Bye")
}

这篇关于如何优雅地停止必须部署的 akka-http 服务器的 actor 系统.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆