apache-camel Throttler组件中的明显错误

时间:2015-11-03 13:56:44

标签: java apache apache-camel throttling

我观察到当rejectExecution(见下文)为true

时,apache-camel并未按预期限制请求
<throttle timePeriodMillis="10000" rejectExecution="true">
    <constant>4</constant>
    <to uri="mock:result"/>
</throttle>

以下是org.apache.camel.processor.Throttle

的代码段
    protected long calculateDelay(Exchange exchange) {
    ......
    TimeSlot slot = nextSlot();
            if (!slot.isActive()) {
                long delay = slot.startTime - currentSystemTime();
                return delay;
            } else {
                return 0;
            }
    }


/*
 * Determine what the next available time slot is for handling an Exchange
 */
protected synchronized TimeSlot nextSlot() {
    if (slot == null) {
        slot = new TimeSlot();
    }
    if (slot.isFull() || !slot.isPast()) {
        slot = slot.next();
    }
    slot.assign();
    return slot;
}

如上所述,只要插槽已满且新请求到达,就会创建在当前插槽之后开始的新插槽,并调用slot.assign()以减少此新创建的插槽的容量以适应当前请求根据我的说法是错误的,因为在处理这个新请求时会有延迟,并且每当有延迟并且rejectExecution = true时,根据Throttler代码 org.apache.camel.processor.ThrottlerRejectedExecutionException被抛出。很明显,即使Throttler组件在达到阈值后拒绝新请求,仍然会减少下一个时隙的容量,这将允许在下一个时隙中处理少一个请求而不是与前一个时隙相同的数量

0 个答案:

没有答案