我正在使用Spring Webflux WebClient在我的Spring boot应用程序中进行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。
请在此处提出建议,并让我知道是否有任何错误之处。