我有一个Flux,对于每个对象,我应该对第三方REST进行API调用(大约1000次调用)。为了防止每秒许多请求我使用:
Flux<Calls> callsIntervalFlux=
Flux.interval(Duration.ofMillis(100))
.zipWith(callsFlux, (i, call) -> call);
// and now Calls emits every 10ms, and REST API is not overloaded
问题是,有时应用程序失败,但有例外:
reactor.core.Exceptions$ErrorCallbackNotImplemented: reactor.core.Exceptions$OverflowException: Could not emit tick 32 due to lack of requests (interval doesn't support small downstream requests that replenish slower than the ticks)
Caused by: reactor.core.Exceptions$OverflowException: Could not emit tick 32 due to lack of requests (interval doesn't support small downstream requests that replenish slower than the ticks)
我是否可以添加任何逻辑来防止错误,或者只是跳过此勾号?
答案 0 :(得分:3)
这意味着结果的消费者并没有足够快地消耗数据:interval
处于固定频率,它试图发出但没有人听。
我认为需要基于Reactor的某种更先进的基于许可证的速率限制器。但与此同时,您可以尝试的另一种简单(简单化?)方法是单独确保每个呼叫从前一个呼叫延迟10毫秒:
Flux<Calls> callsIntervalFlux = callsFlux.delayElements(Duration.ofMillis(10));
(此运算符用于替换zipWith(interval)
模式)