简体   繁体   中英

Spring webclient, how many instances?

I have read in the spring documentation https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-concurrency-model that when using reactor netty for client and server the event loop resources are shared, thats mean that when i create more than one instance of webclient the event loop resources also are shared? If i want to communicate with different APIs from my code should i create multiple Webclient instances or should i share the same instance?

Since WebClient instances are immutable you have no other option than to create for different API's different WebClient's using its built-in builders.

You can copy existing WebClient configurations using mutate() method or create a bare new instance.

See also https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/web-reactive.html#webflux-client and Right way to use Spring WebClient in multi-thread environment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM