Can we use Spring -cloud-netflix and Hystrix to retry a failed excess

I am using the Spring -Cloud-netflix library.

I wonder if there is a way to take this code and add it, instead of immediately executing the backup method to try again N times, and in the case of N times, how to perform the backup method:

 @HystrixCommand(fallbackMethod = "defaultInvokcation")
    public String getRemoteBro(String name) {
        return(executeRemoteService(name));
    }

     private String defaultInvokcation(String name) {
   return "something";
}

Thanks ray.

+4
source share
1 answer

From my comment :

Handle this behavior in code. It’s not the job of histrists 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");
}

, ;) reallyExecuteRemoteService - ServiceReturnMessage .

+2

All Articles