In the latest versions of spring cloud Netflix's official documentation (for example 2.0.2.RELEASE, the last GA version) it states:
When Spring Retry is present, load-balanced RestTemplates, Feign, and Zuul automatically retry any failed requests (assuming your configuration allows doing so).
But that seems wrong concerning the use of standalone Ribbon (i.e. load-balanced RestTemplates). I couldn't make it work nor found any working example. Moreover, I found other sources stating quite the opposite was true, such as:
- spring-cloud with RestTemplate//Ribbon/Eureka - retry when server not available
- Spring Cloud - Getting Retry Working In RestTemplate?).
So, it's the documentation wrong or is the whole world missing something?
We found the same issue; Zuul will neither retry nor failover to alternative servers in the ribbon server list using the default (Apache Http Client) configuration. We tracked it down to this line of code in the
RibbonLoadBalancingHttpClientclass:The hardcoded
false, falseparameters effectively disable retry from ever happening. It is easy to fix this.Add this to your Zuul main application class:
Create a class,
MyRibbonConfigurationand use it to emulate theribbonLoadBalancingHttpClientmethod here except we override and fix thegetRequestSpecificRetryHandlermethod that's causing problems.Adjust
true, trueto reference from properties if you want. With this in place Zuul will start respecting theribbon.MaxAutoRetriesandribbon.MaxAutoRetriesNextServerproperties.Note that if you are using Ribbon with Feign for server->server calls then those Feign calls are not affected because OpenFeign hardcodes those two parameters to
true, true.