【发布时间】:2018-08-06 04:11:07
【问题描述】:
我正在使用 Spring Webflux WebClient 从我的 Spring 启动应用程序进行 REST 调用。并且每次都会在 30 秒内超时。
这是我尝试在 Spring webfulx 的 WebClient 中设置套接字超时的一些代码。
- ReactorClientHttpConnector connector = new ReactorClientHttpConnector(options -> options
.option(ChannelOption.SO_TIMEOUT, 600000).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 600000));
- ReactorClientHttpConnector connector = new ReactorClientHttpConnector(
options -> options.afterChannelInit(chan -> {
chan.pipeline().addLast(new ReadTimeoutHandler(600000));
}));
- ReactorClientHttpConnector connector1 = new ReactorClientHttpConnector(options -> options
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 600000).afterNettyContextInit(ctx -> {
ctx.addHandlerLast(new ReadTimeoutHandler(600000, TimeUnit.MILLISECONDS));
}));
并尝试使用“clientConnector”方法将上述连接器设置添加到“WebClient”中。
并且还尝试如下设置超时:
webClient.get().uri(builder -> builder.path("/result/{name}/sets")
.queryParam("q", "kind:RECORDS")
.queryParam("offset", offset)
.queryParam("limit", RECORD_COUNT_LIMIT)
.build(name))
.header(HttpHeaders.AUTHORIZATION, accessToken)
.exchange().timeout(Duration.ofMillis(600000))
.flatMap(response -> handleResponse(response, name, offset));
以上选项都不适合我。
我正在使用 org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M7,其中包含 org.springframework:spring-webflux:5.0.2.RELEASE 的依赖关系。
请在这里提出建议,如果我在这里做错了什么,请告诉我。
【问题讨论】:
-
为什么需要 10 分钟的超时时间?
-
这只是为了测试目的。如果我能够设置超时,那么我将根据我的应用程序对这个时间进行基准测试。
标签: java spring spring-boot timeout spring-webflux