如果外部服务在不同的情况下抛出不同的异常,那么你可能可以像这样忽略这些异常
@HystrixCommand(ignoreExceptions = {SomeException.class})
但是,如果您必须根据错误消息忽略异常,那么解决此问题的最佳方法是在您的外部调用周围放置一个 try catch。并在 catch 块中检查它是否是需要忽略的异常之一。如果是这样,不要做任何事情。如果不重新抛出此异常。这样的事情会做。更多关于HystrixBadRequestException的信息
@HystrixCommand(fallbackMethod = "fallBackMethod", groupKey = "CircuitBreaker", commandKey = "somekey", threadPoolKey = "somekey",
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "10000"),
@HystrixProperty(name = "execution.timeout.enabled", value = "false"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "20"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "1200000"),
},
threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "180000")
})
public void someMethod(....){
try {
// Call external service
} catch(Exception e) {
if(exception to be ignored)
throw new HystrixBadRequestException("Some message", e);
else
throw e
}
}