2


Recently I've been instructed to define some fallback for our existing feign clients in our spring boot projects. I did some research and apparently Hystrix is the way to go.

After integrating it with the project, I noticed that every time I don't received desired response from the target service (for example when I receive a response with http status 403 instead of 200) , client switches to fallback method.
Well, That is not the desired flow in our case. After searching for solutions I did find out that HystrixCommands are the proper way to handle this problem. According to this I could use @HystrixCommand to prevent triggering the fallback.
I did so but it does not appear to be working.
My question is how can I configure hystrix to suite my needs.

Here is simple version of what I've came up with so far:

@FeignClient(name="test-client", fallback=TestClientFallback.class)
public interface TestClient
{
   //---I have emplemented a custom FeignDecoder to throw TestException
   @HystrixCommand(ignoreExceptions=TestException.class)
   Boolean isUserActive(Integer userId);

   public class TestClientFallback implements TestClient
   {
      @Override
      public Boolean isUserActive(Integer)
      {
          //---default fail over scenario
      }
   }

}

Thanks in advance.

M-Soley
  • 265
  • 1
  • 4
  • 13
  • Considering you are adding hystrix to the project (and not changing some code that already uses hystrix) I believe is worth to take a look at resilience4j https://github.com/resilience4j/resilience4j. Hystrix is no longer in active development, they even recommend resilience4j for new projects :) – V. Lovato Jul 20 '21 at 02:42

0 Answers0