How to retry with hystrix
Asked Answered
M

2

16

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?

Mohammedanism answered 20/10, 2017 at 11:12 Comment(0)
M
20

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.

Muzzle answered 20/10, 2017 at 12:0 Comment(2)
Is it a good idea to use HystrixCommand and Retryable (from spring retry) over the same method? @MuzzleGraff
If you have a new project, I would always advice to use resilience4j because Hystrix is now 4 years unmaintained. But yes technical it should work what you ask for.Muzzle
A
-2

If you use feign for API calls, it supports retrying. You can only execute other logic in the fallback method, and leave the retrying logic to feign.

You can refer to this link: https://medium.com/swlh/how-to-customize-feigns-retry-mechanism-b472202be331

Antofagasta answered 28/6, 2021 at 9:49 Comment(1)
please include all information relevant to your answer in your post. external links should only provide additional information. right now, if the link ever breaks for some reason, your answer becomes completely useless. i recommend taking the tour as well as reading how to write a good answerCherycherye

© 2022 - 2025 — McMap. All rights reserved.