I am using Spring-Cloud-netflix library.
I wonder if there is a way to take this code and add configure it instead of executing the fallback method right away to retry to execute it N times and in case of N times than execute the fallback method:
@HystrixCommand(fallbackMethod = "defaultInvokcation")
public String getRemoteBro(String name) {
return(executeRemoteService(name));
}
private String defaultInvokcation(String name) {
return "something";
}
Thanks, ray.
I have a hystrix command that encapsulates a REST call. In case of failure(e.g. timeout), I want to make a single retry and return an appropriate error if it still fails. As I can see, Hystrix doesn't support retries. The only way to do it with Hystrix is to put the main logic into getFallback() method.
Hystrix helps by providing protection and control over latency and failure from dependencies, most commonly those accessed over network. It helps stop cascading failures and allows you to fail fast and rapidly recover, or fallback and gracefully degrade.
Akka, Envoy, Istio, Zuul, and Polly are the most popular alternatives and competitors to Hystrix.
Hystrix Status. Hystrix is no longer in active development, and is currently in maintenance mode. Hystrix (at version 1.5. 18) is stable enough to meet the needs of Netflix for our existing applications.
From my comment:
Handle this behavior in your code. It's not the job of hystrix to know your "special" business logic. As an example
private final static int MAX_RETRIES = 5;
@HystrixCommand(fallbackMethod = "defaultInvokcation")
public String getRemoteBro(String name) {
return(executeRemoteService(name));
}
private String executeRemoteService(String serviceName) {
for (int i = 0; i < MAX_RETRIES; i++) {
try {
return reallyExecuteRemoteService(serviceName);
} catch (ServiceException se) {
// handle or log execption
}
}
throw new RuntimeException("bam");
}
Don't know if you prefer to use an exception inside the loop ;) You could also wrap your answer from reallyExecuteRemoteService
in some kind of ServiceReturnMessage with a status code.
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