问题
I have a Flux, for each object I should make an API call to the third party REST (about 1000 calls). To prevent to many requests per second Im using:
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
The problem is, sometimes application fails with exception:
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)
Is there any logic that I can add to prevent an error, or just skip this tick?
回答1:
This means that the consumer of the results doesn't consume the data fast enough: the interval
being on a fixed frequency, it tries to emits but nobody listens.
There's a need for some sort of more advanced permit-based rate limiter built on Reactor I think. But in the meantime, another simple (simplistic?) approach that you could try is to individually ensure each call is delayed from the previous one by 10ms:
Flux<Calls> callsIntervalFlux = callsFlux.delayElements(Duration.ofMillis(10));
(this operator was made to replace the zipWith(interval)
pattern)
来源:https://stackoverflow.com/questions/48520084/spring-webflux-reactor-error-when-zipwith-could-not-emit-tick-due-to-lack-o