我观察到当rejectExecution
(见下文)为true
<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组件在达到阈值后拒绝新请求,仍然会减少下一个时隙的容量,这将允许在下一个时隙中处理少一个请求而不是与前一个时隙相同的数量