首页 > 解决方案 > Apache骆驼ThrottlingExceptionRoutePolicy失败重置

问题描述

ThrottlingExceptionRoutePolicy .failures 在 failureWindow(time) 之后不断增加。说 failureWindow=1000 和 failureThreshold=10。这意味着如果在 1 秒内出现 10 次故障,则断开断路器。

  public void onExchangeDone(Route route, Exchange exchange) {
    if (this.keepOpen.get()) {
        if (this.state.get() != 2) {
            LOG.debug("opening circuit b/c keepOpen is on");
            this.openCircuit(route);
        }
    } else {
        if (this.hasFailed(exchange)) {     //#1
            this.failures.incrementAndGet();
            this.lastFailure = System.currentTimeMillis();
        }
        this.calculateState(route);
    }

}

protected boolean isThresholdExceeded() {
    boolean output = false;
    this.logState();
    if (this.failures.get() >= this.failureThreshold && this.lastFailure >= System.currentTimeMillis() - this.failureWindow) {
    output = true;
    return output;
}

在每个 #1(hasFailed=true) 上,无论时间窗口如何,this.failures 都会增加。现在假设在一个小时的时间段内出现 10 个异常,calculateState 将在第 10 个异常打开电路,因为 failures >= failureThreshold 并且 lastFailure 时间在 failureWindow 内。只有在调用 closeCircuit 时才会重置失败。

它是一个错误吗?我想知道它有什么用?如果您正在使用它,请分享您的见解。

标签: apache-camelevent-drivencircuit-breakerapache-camel-3

解决方案


推荐阅读