我正在尝试在vert.x Web客户端中设置requestTimeout。但是它没有按预期工作。
响应时间<10毫秒的api从Web客户端设置了100毫秒requestTimeout超时。服务器和客户端都在我的本地计算机上运行。
@Test
public void connectionTimeOut() throws InterruptedException {
WebClient client = WebClient.create(Vertx.vertx());
client.request(HttpMethod.GET,8000 , "localhost", "/scripts/").timeout(100).send(ar -> {
if (ar.succeeded()) {
System.out.print("Request succeded");
} else {
ar.cause().printStackTrace(); ;
}
});
TimeUnit.MINUTES.sleep(20);
}
java.util.concurrent.TimeoutException: The timeout period of 100ms has been exceeded while executing GET /scripts/ for host localhost
at io.vertx.core.http.impl.HttpClientRequestBase.timeout(HttpClientRequestBase.java:183)
at io.vertx.core.http.impl.HttpClientRequestBase.handleTimeout(HttpClientRequestBase.java:168)
at io.vertx.core.http.impl.HttpClientRequestBase.lambda$setTimeout$0(HttpClientRequestBase.java:126)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:870)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:829)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:344)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
如果将requestTimeout设置为1000ms,则相同的代码有效。请让我知道是否有任何解决方法,或者我缺少什么。