@PostConstruct
public void initCommonWebClient() {
Function<HttpClient, HttpClient> mapper = client -> {
HttpClient httpClient = HttpClient.create()
.tcpConfiguration(tcpClient ->
// 连接超时为60秒
tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1 * 60 * 1000)
.doOnConnected(conn -> conn
// 读取超时为60秒
.addHandlerLast(new ReadTimeoutHandler(60))
// 写入超时为60秒
.addHandlerLast(new WriteTimeoutHandler(60)))
.proxy(typeSpec -> typeSpec.type(ProxyProvider.Proxy.HTTP)
.address(new InetSocketAddress("127.0.0.1", 8888))));
return httpClient;
};
commonWebClient = webClientBuilder.clientConnector(new ReactorClientHttpConnector(reactorResourceFactory, mapper))
.codecs(clientCodecConfigurer ->{
clientCodecConfigurer.customCodecs().register(new Jackson2JsonDecoder());
clientCodecConfigurer.customCodecs().register(new Jackson2JsonEncoder());
clientCodecConfigurer.customCodecs().register(new Jaxb2XmlEncoder());
clientCodecConfigurer.customCodecs().register(new Jaxb2XmlDecoder());
})
.build();
}