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) {
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?
java spring-boot spring-cloud hystrix
Johan
source share