Spring Web客户端,有多少实例



我已经阅读了spring文档https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-并发模型,当使用reactor-netty作为客户端和服务器时,事件循环资源是共享的,这意味着当我创建多个webclient实例时,事件环路资源也是共享的?如果我想从代码中使用不同的API进行通信,我应该创建多个Webclient实例还是应该共享同一个实例?

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

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

另请参阅https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/web-reactive.html#webflux-客户端和在多线程环境中使用SpringWebClient的正确方法

最新更新