我想設置超時我的WebClient超時,這裏是當前的代碼:春天5 webflux如何設置Web客戶端
SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
ClientHttpConnector httpConnector = new ReactorClientHttpConnector(opt -> {
opt.sslContext(sslContext);
HttpClientOptions option = HttpClientOptions.builder().build();
opt.from(option);
});
return WebClient.builder().clientConnector(httpConnector).defaultHeader("Authorization", xxxx)
.baseUrl(this.opusConfig.getBaseURL()).build();
我需要添加超時,也合併策略,我想類似的東西:
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(this.applicationConfig.getHttpClientMaxPoolSize());
cm.setDefaultMaxPerRoute(this.applicationConfig.getHttpClientMaxPoolSize());
cm.closeIdleConnections(this.applicationConfig.getServerIdleTimeout(), TimeUnit.MILLISECONDS);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(this.applicationConfig.getHttpClientSocketTimeout())
.setConnectTimeout(this.applicationConfig.getHttpClientConnectTimeout())
.setConnectionRequestTimeout(this.applicationConfig.getHttpClientRequestTimeout()).build();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).setConnectionManager(cm).build();
但我想不出如何設置的HttpClient在我的WebClient
這似乎是我尋找,只是一個簡單的問題是,連接超時或請求超時。任何想法如何設置連接池大小?感謝您的幫助 – Seb
'reactor.ipc.netty.options.ClientOptions.Builder'中有'poolResources()''requestTimeout'確實等於'ChannelOption.SO_TIMEOUT'。 'connectTimeoutMillis'肯定是關於連接的。 –
是的,我看到poolResources(),我不得不承認我不知道如何使用它:/任何想法? – Seb