Polling implemented using reactor

34 views
Skip to first unread message

Ayush Verma

unread,
Sep 5, 2017, 7:19:40 AM9/5/17
to reactor-framework

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.


Stack-exchange link.

Reply all
Reply to author
Forward
0 new messages