Reputation: 158
Is there a way to get a message in actor supervisor's SupervisorStrategy? I mean the one that caused actor's failure. I want to get some data from it.
Upvotes: 5
Views: 993
Reputation: 40461
A possible approach:
For instance:
// 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
}
Upvotes: 4