在配置Spring WebClient代理时如何更改DEFAULT_CONNECT_TIMEOUT_MILLIS?

时间:2019-10-24 15:57:31

标签: java spring kotlin spring-webflux spring-webclient

我正尝试通过代理(kotlin)用代理配置WebClient:

private fun WebClient.Builder.securedHttpConnector(
    host: String,
    port: Int,
    sslContextBuilder: SslContextBuilder
) =
    apply {
        clientConnector(
            ReactorClientHttpConnector(
                HttpClient
                    .create()
                    .secure { sslContextSpec -> sslContextSpec.sslContext(sslContextBuilder) }
                    .tcpConfiguration { tcpClient ->
                        tcpClient.proxy {
                            it
                                .type(ProxyProvider.Proxy.HTTP)
                                .address(InetSocketAddress(host, port))
                        }
                    }
            )
        )
    }

但是ProxyHandler.java中的默认timout是10000毫秒。我该如何更改?合作伙伴系统给出的响应时间长于10秒钟,我收到以下异常:

io.netty.handler.proxy.ProxyConnectException: http, none, /<proxy host>:<proxy port> => /<target host>:<target port>, timeout
at io.netty.handler.proxy.ProxyHandler$2.run(ProxyHandler.java:201) ~[netty-handler-proxy-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:127) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:163) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:405) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_212]

1 个答案:

答案 0 :(得分:0)

您可以使用选项ChannelOption.CONNECT_TIMEOUT_MILLIS参见documentation