Skip to content
Advertisement

How to retry with hystrix

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. But it doesn’t look to be correct.

So, what is a proper way to implement timeout with hystrix?

Advertisement

Answer

Hystrix itself does not care what kind of command gets wrapped by it and it does not support the idea of retries. Example behind the idea: If your command (that wraps a REST request) is parametrised it could be that some resource endpoints should be retried while others not. It won’t be nice to have either two commands that do more or less the same nor a technical parameter to activate a retry. Additionally this will add some extra complexity to the project.

To get around this problem and stick with Hystrix you might want to take a look into SpringRetry if you are working on a Spring application.

Another possible solution is resilience4j which could be seen as a combination of Hystrix and SpringRetry in this context.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement