有没有办法在 Actor 主管的 SupervisorStrategy 中获取消息?我的意思是导致 Actor 失败的那个。我想从中获取一些数据。
最佳答案
一种可能的方法:
例如:
// The new exception type
case class MessageException(
akkaMessage: Any,
originalException: Throwable
) extends RuntimeException("Exception due to message")
// In the supervised actor
def receive = {
case msg => try{ process(msg) } catch {
case t => throw MessageException(msg,t)
}
}
// In the supervisor
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case MessageException(msg,t) => //decide what to do
}
关于scala - Akka - 是否有可能在 Actor 的主管中收到有关它失败的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22142123/