I have a feign client that sends one request to another microservice every 60 seconds. On this controller, I use the HystrixCommand annotation with a user configuration (just experimenting). I also have a fallback method in which I go into when the request fails. However, the expected data is quite sensitive for me, so it makes no sense to send empty data from the fallback method.
Question: How to execute a failed request another 2-3 times at any interval? Does Hystrix have this functionality?
I had the idea to call the request again in the fallback method and save somewhere the number of executed requests, each time comparing them with the limit-variable, but I do not like it.
@HystrixCommand(
threadPoolKey = "currencyThreadPool",
threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"),
@HystrixProperty(name = "maxQueueSize", value = "10")},
commandProperties = {
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "90"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "15000"),
@HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "5")}
)
In the end, I used Spring Retry library, which fully satisfied my requirements.
@Retryable(value = {ConnectException.class, FeignException.class}, maxAttempts = 4,
backoff = @Backoff(delay = 5000, maxDelay = 80000, multiplier = 4))