骆驼Hystrix EIP-IgnoreException防止调用回退

时间:2019-01-11 17:49:56

标签: java apache-camel hystrix

在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");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

当前未在camel-hystrix中实现。我已经记录了一张票,可以在即将发布的版本中添加此票:https://issues.apache.org/jira/browse/CAMEL-13066