1
\$\begingroup\$

I have a use case where I need to poll a certain service till all data has arrived. The service accepts a list of ids and responds with data corresponding to these ids. Data is asynchronously made available by an external service and currently polling is the only option. There is an overall time out of 1min.

return Mono.fromSupplier(() -> poll(ids))
                   //poll every 2 seconds, poll 25 times (total 50 secs)
                   .repeatWhen(completed -> completed.zipWith(Flux.range(1, 25)).delayElements(Duration.ofSeconds(2)))
                   //stop polling if all responses have arrived
                   .takeUntil(PollingService::isCompleted)
                   //slow producer fast consumer scenario
                   .subscribeOn(Schedulers.elastic())

I have tried to delegate the polling to reactor as much as possible and my understanding is that this will be more efficient than doing it on a single thread and blocking it for the whole duration.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.