How to handle the expected errors in case of failure of the histogram?

We have a Hystrix command (1.4.x) that looks like this (using Spring):

@HystrixCommand(groupKey = "GroupKey", commandKey = "CommandKey", fallbackMethod = "myFallback") public List<X> findXs(long xId) { return externalService.findXsExternally(xId); } 

In fact, we do not want to return the (empty) List from the backup method, but rather throw an exception so that the calling findXs knows that the externalService not working and can take action accordingly. But at the same time, we would like to take advantage of the benefits that Hystrix provides. In our case, we want the caller to return an error message instead of returning a list. Spring backs up as follows:

 public List<X> myFallback(long xId) { // What to do?? Throw exception!? } 

Throwing an exception from myFallback "works", but Hystrix will warn us that:

CommandKey error and backup error.

those. he will interpret this as a failed failure. In our case, the exception should not be interpreted as an unsuccessful failure, but rather as the expected behavior. We also tried to wrap the thrown exception in a HystrixBadRequestException , but it doesn't seem to work for backups (according to docs , this works for the "run" method).

How to implement an implementation exception method in Hystrix? Can we safely ignore the warning or have Hystrix not developed this work?

+7
java spring-boot spring-cloud hystrix
source share
1 answer

Why do you even set up a reserve if you do not want to use it? Hystrix does not require you to install it. Redundancy is used when you prefer to return something like stale data from the cache rather than throw an exception. Both cases are considered a Hystrix error. If you chose to exclude from the backup method, you would only confuse Hystrix, who would think that there was an error with your backup in addition to the service itself. Hystrix should throw a HystrixBadRequestException, which throws an exception from the findXs method if you do not provide a backup.

+9
source share

All Articles