Spring WebFlux (reactor). Error when zipWith - Could not emit tick due to lack of requests

心不动则不痛 提交于 2020-08-08 09:39:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!