I am using AKKA.NET in my current .NET project.
My question is: how do experienced AKKA developers implement the replay-message-on-failure pattern using the latest AKKA libraries for Java or .NET?
Here are a few more details.
I want to make sure that the error message (i.e. the message received by the actor leading to the exception) is replayed / repeated several times with a time interval between them. Typically, an actor is reloaded with a failed message.
I wrote my own helper method like this to solve it:
public void WithRetries(int noSeconds, IUntypedActorContext context, IActorRef receiver, IActorRef sender, Object message, Action action) { try { action(); } catch (Exception e) { context.System.Scheduler.ScheduleTellOnce(new TimeSpan(0, 0, noSeconds), receiver, message, sender); throw; } } }
Now my actors usually look like this:
Receive<SomeMessage>(msg => { ActorHelper.Instance.WithRetries(-1, Context, Self, Sender, msg, () => { ...here comes the actual message processing }); });
I like the above solution because it is simple. However, I don't like the fact that it adds another layer of indirection in my code, and the code gets a little messier if I use this helper method in many places. In addition, it has some limitations. First of all, the number of repetitions is not regulated by an auxiliary method. It is governed by the supervisor's oversight strategy, which, I believe, is messy. In addition, the time interval is fixed, while in some cases I would like the time interval to increase for each repetition.
I would prefer something that can be configured using HOCON. Or something that can be used as a cross-concern.
I can see various offers for AKKA for Scala, AKKA for Java and AKKA.NET. I saw examples with routers, examples with Circuit Breaker (e.g. http://getakka.net/docs/CircuitBreaker#examples ), etc. I also saw a few examples using the same idea as above. But I feel that it should be even easier. Perhaps this is due to the use of ACKA Persistence and events.
So, to repeat my question: how do experienced AKKA developers implement the replay-message-on-failure pattern using the latest AKKA libraries for Java or .NET?