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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With