【发布时间】:2019-06-06 16:17:39
【问题描述】:
在 Apache camel Hystrix EIP 中,我们如何防止对 bad request 异常的 fallback 方法的调用。我尝试从我的请求调度程序处理器中抛出“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");
}
}
}
【问题讨论】:
标签: java apache-camel hystrix