在Apache骆驼Hystrix EIP中,如何防止由于错误的请求异常而调用回退方法。我尝试从请求调度程序处理器中抛出“ HystrixBadRequestException”,但我仍然看到触发回退。有什么办法解决这个问题?
/* in route builder class */
public void configure() throws Exception {
.hystrix()
.hystrixConfiguration()
.circuitBreakerEnabled(circuitBreakerConfig.isEnabled())
.executionTimeoutInMilliseconds(circuitBreakerConfig.getConnectionTimeoutInMilliseconds())
.circuitBreakerErrorThresholdPercentage(circuitBreakerConfig.getErrorThresholdPercentage())
.circuitBreakerSleepWindowInMilliseconds(circuitBreakerConfig.getSleepWindowInMilliseconds())
.circuitBreakerRequestVolumeThreshold(circuitBreakerConfig.getRequestVolumeThreshold())
.metricsRollingStatisticalWindowInMilliseconds(circuitBreakerConfig.getRollingPercentileWindowInMilliseconds())
.end()
.to("requestDispatcher")
.onFallback()
.log(LoggingLevel.INFO, "Fallback:")
.bean("responsehandler", "getFallbackResponse")
.stop()
.end()
}
/* in dispatcher class */
private Exchange dispatchRequest(Exchange exchange) {
if (exception instanceof HttpOperationFailedException) {
Integer statusCode = ((HttpOperationFailedException) exception).getStatusCode();
if(statusCode == 400) {
throw new HystrixBadRequestException("Hystrix bad request");
}
}
}
最佳答案
目前尚未在camel-hystrix中实现。我已记录了一张票,以在即将发布的版本中添加此票:https://issues.apache.org/jira/browse/CAMEL-13066