是vertx webclient.send()方法阻止还是非阻滞
我有一个 Verticle,它有一个处理程序,可以在事件循环线程中调用 Vertx 的 Webclient。实际的底层API调用是同步的还是异步的?它会阻塞我的事件循环线程吗?假设我的 API 调用需要 30 秒才能返回。
public class MyHandler implements Handler<Message<JsonObject>> {
WebClient myClient;
public MyHandler(WebClient myClient) { this.myClient = myClient; }
@Override
public void handle(Message<JsonObject> message) {
myClient
.get("url.com/the/path")
.send().onSuccess(result -> { message.reply(result.bodyAsJson()); }
}
}
我是否需要使用 Vertx.executeBlocking(p -> {/此处调用 api/}) 来包装 Webclient 调用? API调用是否阻塞?请注意,我的垂直体是常规垂直体,而不是工作垂直体。
I have a verticle which has a handler that calls Vertx's Webclient in the event loop thread. Is the actual underlying API call synchronous or asynchronous? Does it block my event loop thread? Assume my API call takes 30 seconds to return.
public class MyHandler implements Handler<Message<JsonObject>> {
WebClient myClient;
public MyHandler(WebClient myClient) { this.myClient = myClient; }
@Override
public void handle(Message<JsonObject> message) {
myClient
.get("url.com/the/path")
.send().onSuccess(result -> { message.reply(result.bodyAsJson()); }
}
}
Do I need to wrap the webclient call with Vertx.executeBlocking(p -> {/api call here/})? Is the API call blocking? Note that my verticle is a regular one not a worker verticle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有i/o或可能长期运行的vert.x apis都是异步的。因此,
发送
呼叫将立即返回,然后将您传递给OnSuccess
的回调将在收到响应后安排。其他代码将能够在请求正在待处理的30秒内以同一线程执行。如 vert.x docs :
All Vert.x APIs that do I/O or could otherwise be long-running are asynchronous. So that
send
call will immediately return, and the callback you passed toonSuccess
will be scheduled by Vert.x once the response is received. Other code will be able to execute in the same thread in the 30 seconds the request is pending.As stated in the Vert.x docs: