Given I create my WebClient using the builder() pattern, e.g. somewhat like this:
WebClient.builder()
.uriBuilderFactory(defaultUriBuilderFactory)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.USER_AGENT, USER_AGENT)
.defaultHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate")
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(clientCodecConfigurer -> clientCodecConfigurer
.defaultCodecs()
.maxInMemorySize(16 * 1024 * 1024))
.build())
.build();
Is there any possibility to do rate limiting within the WebClient itself?
I saw some answers, that I can do the rate limiting when I do the request. I would rather define it within the WebClient, because the same WebClient is used for different requests, so I need to set an overall rate limit for this WebClient.
By "rate limit" I mean: How many requests this WebClient is allowed to send per second. For example: I want to limit this WebClient to only send 5 requests per second.
If this is not possible using the WebClient, are there any alternatives that make sense?