Spring webclient,有多少个实例?

时间:2018-11-07 20:11:02

标签: java spring spring-webflux reactive

我在春季文档https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-concurrency-model中已经读到,当将Reactor Netty用于客户端和服务器时,事件循环资源是共享的,这意味着当我创建多个webclient实例时,事件循环资源也将共享? 如果我想使用代码中的不同API进行通信,我应该创建多个Webclient实例还是应该共享同一实例?

1 个答案:

答案 0 :(得分:1)

由于WebClient实例是不可变的,因此除了使用内置的构建器为不同API的不同WebClient创建之外,您别无选择。

您可以使用mutate()方法复制现有的WebClient配置或创建一个全新的实例。

另请参阅https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/web-reactive.html#webflux-clientRight way to use Spring WebClient in multi-thread environment