java - Spring 的 WebClient 的连接和套接字超时会引发哪个异常?
问题描述
我正在通过 a 设置连接、套接字、读取和写入超时,reactor.netty.tcp.TcpClient
如下面的代码片段所示。在读取或写入超时时会抛出io.netty.handler.timeout.ReadTimeoutException
or 。WriteTimeoutException
连接和套接字超时会引发哪个异常?
// configuration of timeouts
HttpClient httpClient = HttpClient.create()
.tcpConfiguration(client -> client
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2_000)
//.option(ChannelOption.SO_TIMEOUT, 2_000) // SO_TIMEOUT not supported
.doOnConnected(conn -> conn
.addHandlerLast(new ReadTimeoutHandler(2_000, TimeUnit.MILLISECONDS))
.addHandlerLast(new WriteTimeoutHandler(2_000, TimeUnit.MILLISECONDS))));
ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
// build the web client
WebClient webClient = WebClient.builder()
.clientConnector(connector)
.baseUrl("http://localhost:8081")
.build();
// perform the GET-request (throws ReadTimeoutException, WriteTimeoutException)
List<MyEntity> responseList = this.nominatimWebClient.get()
.uri("/query")
.retrieve().bodyToMono(new ParameterizedTypeReference<List<MyEntity>>() {}).block();
编辑:这个警告出现在我的日志中,所以我不再使用 SO_TIMEOUT 了:
io.netty.bootstrap.Bootstrap: Unknown channel option 'SO_TIMEOUT' for channel '[id: 0xbb2d06f5]'
解决方案
推荐阅读
- swift - SpriteKit - 如何使用计时器过渡到新场景
- angular - 在角度 6 中绑定多个 for 循环内的值
- c++ - 背景图片未绘制 QWidget
- python - 自 Matplotlib 更新以来重叠的子图标题
- javascript - 使用第一个列单元格输入值复制所有列单元格输入值
- css - 减:不能在每个内部使用 Map
- android - 检索缓存的转换后的 AAR 依赖 classes.jar
- cython - Cython 中的对象数组:希望先阅读文档
- java - Eclipse - 带有 Tomcat 的 Maven 项目收到 404 错误
- android - 谷歌身份验证仅在调试中起作用