0

我正在尝试使用代理配置 WebClient 的下一种方式(kotlin):

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]
4

1 回答 1

0

您可以使用选项 ChannelOption.CONNECT_TIMEOUT_MILLIS 查看文档

于 2019-10-25T16:58:36.743 回答