java - Camel Hystrix EIP - IgnoreExceptions 以防止调用 Fallback

标签 java apache-camel hystrix

在Apache Camel Hystrix EIP中,如何防止调用错误请求异常的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");
        }
    }
}

最佳答案

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

关于java - Camel Hystrix EIP - IgnoreExceptions 以防止调用 Fallback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54151657/

相关文章:

java - 为什么我的服务在 Android 中不起作用? (我只想每 5 秒记录一次)

java - (R.layout.splash);飞溅无法解析或不是一个字段

java - 使用 Camel Jetty 进行基本身份验证

java - Hystrix 命令失败并显示 "timed-out and no fallback available"

java - 从另一个类访问的静态 ArrayList 始终为空

java - 尝试在 spring mvc 中创建并保存对象列表

apache-camel - 在 Apache Camel 中处理大型 CSV 文件的最佳策略

java - Apache Camel : Adding parameters to throwException statement

java - Hystrix 和自定义异常