Reputation: 51
I want to use Spring WebClient in a project to consume some external web service.
WebClient
object be singleton or shared among all threads (requests)?mono.block()
internally work similar to future.get()
or latch.await()
?Upvotes: 1
Views: 6706
Reputation: 44368
The WebClient
is a non-blocking implementation of a REST client built on the Reactive Stack, so I guess the only issue you should focus on is to complete a non-blocking call.
- Can WebClient object be a singleton or shared among all threads (requests)?
A standard way I have seen everywhere is to inject WebClient
as a bean. I find no reason to do any different.
@Autowired
WebClient webClient;
- If my application is going to get millions of requests per second, then do I need to pool WebClient Objects?
That's a lot! This should definitely need to be solved with service replication, load-balancers, bulkhead, etc. In terms of the client itself, see the following performance of reactive client using newer versions of Spring: WebFlux Reactive Programming Performance Test. Moreover, that is the expected maximal throughput?
- Does mono.block() internally work similar to future.get() or latch.await()?
Yes, it does.
Upvotes: 2