我有两个演员:
ProcessManager处理系统中的一些流程(例如,用户注册、购买等)
通知程序- 如果 ProcessManager 发生错误,应通知用户。我需要捕获 ProcessManager 参与者的失败(它失败并因任何原因停止,例如,由于 ActorInitializationException 或达到最大重启时间并且流程管理器参与者已停止)。
class ProcessManager extends Actor {
override def receive: Receive = {
...
}
}
class Notifier extends Actor {
override def receive: Receive = {
PROCESS MANAGER ACTOR FAILED AND STOPPED =>
// Here I need to catch failure of ProcessManager actor
// (it was failed and stopped for what ever
// reason, for example, because of ActorInitializationException
// or max restart time reached and Process manager actor was stopped).
//
// Then do some stuff, for example, send message to the client via web socket.
}
}
class MyController @Inject() (cc: ControllerComponents, actorSystem: ActorSystem)
(implicit exec: ExecutionContext) extends AbstractController(cc) {
// I need to catch failure of processManager in this actor.
val notifier = actorSystem.actorOf(Props(classOf[Notifier]))
def registerUser = Action.async {
// Actor may be stopped because of ActorInitializationException here
val processManager = actorSystem.actorOf(Props(classOf[ProcessManager]))
...
// OR it may be stopped here for any reason.
processManager ! "some message which will fail and stop pm actor"
Future.successfull(Ok("Thanks."))
}
}
如何在Notifier角色中捕获ProcessManager角色的终止(由于失败) ?
编辑 让我解释一下我的问题的背景。
我在 Play 控制器中创建 PM actor 并将消息发送给它(Tell),然后我立即向用户返回 Ok 响应。PM actor 创建另一个子actor,并在创建过程中抛出 ActorInitializationException。我需要通知用户(通过 Web 套接字,使用 Notifier Actor)出现问题。