[Note: This blog has been updated on 22nd August 2013, after the valuable feedback of readers.]
In this blog, I have explained a simple way to implement retry support for Akka future in Scala.
When Akka actor dies for any reason and we try to receive response from Akka future, this implementation would work.
Here is the logic:
When Akka future fails to respond, this retry logic would start automatically and would work until result is obtained or until number of retry limit is finished.
If we would not provide any limit, this would work indefinitely until result is obtained.
A sample call to this method :-
Here number of retry limit is 10. So above call would hit retry method 10 times. If limit is over and actor is not reachable,
retry method would return None as future response.
You can return default result according to your requirement.
After getting Future, you can use the
mapTo method to safely cast a Future to an expected type. This will return the result, if the cast is successful. Otherwise it will return
If you have implemented any better approach, please suggest.
Any suggestion would be appreciated.