1

Is there any operator similar to limitRate for publisher, which can be used to limit the number of parallel requests being processed by Webclient?

Suppose the downstream service might respond in few seconds. delayElements might be used to delay each request by few milliseconds. but the request will start processing after the delay, while the other requests are being processed. This will overload the service provider.

Scenario - Fast Producer, Slow Consumer

Thought this is related to original question.

How to limit the request/second with WebClient?

Edit:

I added the concurrency level to flux flatmap and wanted to rate limit the request to webclient in flatMap. But the concurrency level had no impact on requests to webclient.

Wrote below code to simulate the behavior.

List<Flux<Integer>> fluxList = List.of(Flux.range(1, 300), Flux.range(301, 300), Flux.range(601, 300));
Flux.mergeSequential(fluxList, 2, 2)
                .flatMap(i -> webClient.get().uri("/some-uri", 2)
                .retrieve().toEntity(Map.class)
                .doOnSuccess(mapResponseEntity -> System.out.println(Thread.currentThread().getName() + " value in flat map : "+i)).subscribeOn(Schedulers.boundedElastic())
                ).subscribe();

Could someone please let me know how to rate limit the request in above code?

Gurmin
  • 43
  • 6

0 Answers0