quarkus jaxrs 非阻塞误解
quarkus jaxrs non-blocking misconception
据我所知:
- this quarkus documentation,quarkus 正在使用工作线程来执行 jaxrs 端点。
- this vert.x documentation,工作线程设计用于调用阻塞代码。
可能是误解:以下术语到底是什么意思?
- 服务器非阻塞代码。
- 服务器异步响应处理。
- 服务器反应代码。
我的问题是:为什么我不能使用 jax-rs 端点创建非阻塞代码并利用标准事件循环线程?
编辑:
有几个问题困扰着我:
Resteasy is not async by default, but it is capable of handling non blocking async response
async by default
和is capable of handling non blocking async response
有什么区别?
- 从这里,我发现任何 JAX-RS 实现都能够处理非阻塞异步响应,因为
@Suspended
是一个 JAX-RS 注释,不是吗?
我认为 this article 很好地解释了这些概念的含义。
编辑 2:
另一边,根据Quarkus Http documentation,它说:
All the HTTP requests your application receive are handled by event loops (IO Thread) and then are routed towards the code that manages the request. Depending on the destination, it can invoke the code managing the request on a worker thread (Servlet, Jax-RS) or use the IO Thread (reactive route).
在这里,我发现默认情况下,所有 JAX-RS "endpoints" 都由 工作线程(工作垂直?) 处理,因为它们是阻塞的默认情况下。
根据 vert.x 文档:
By default blocking code is executed on the Vert.x worker pool.
我现在的问题是:
- 正如我们之前提到的,我们可以使用
AsyncResponse
使 jax-rs "endpoint" 成为非阻塞的。现在当 jax-rs 端点进入阻塞代码时是否必须使用工作线程?
- a "quarkus worker thread" 等同于 "vert.x worker verticle"?
JAX-RS 只是一个标准。 Quarkus 使用 RESTEasy 作为 JAX-RS 实现。 RESTEasy 使用阻塞 API:
Resteasy is not async by default, but it is capable of handling non
blocking async response, specially with Vert.x
您可以在这里阅读更多相关信息:https://github.com/vert-x3/vertx-examples/tree/master/resteasy-examples
RESTEasy 是 JBoss 的一部分。 JBoss 是 Red Hat 的一部分。 Quarkus 也是一个 Red Hat 项目。
理论上,您可以使用另一个非阻塞的 JAX-RS 实现。但是我什么都不知道,原因很简单——JAX-RS 已经过时了。
像async by default
这样的东西可能意味着很多不同的东西。就 Vert.x 而言,这意味着大多数 API 要么期待回调,要么 return 某种未来(Deferred value
,如果你愿意的话)。
已经确定,is capable of handling non blocking async response
意味着默认情况下,JAX-RS 会阻塞直到值被 returned,但从技术上讲,可以将其包装在一种 deferred value
也。这就是 Vert.x RestEasy 集成的作用。
@Suspended
,或更具体地说,AsyncResponse
是包装这些值的另一种方式,尽管比其他方式更骇人听闻。
据我所知:
- this quarkus documentation,quarkus 正在使用工作线程来执行 jaxrs 端点。
- this vert.x documentation,工作线程设计用于调用阻塞代码。
可能是误解:以下术语到底是什么意思?
- 服务器非阻塞代码。
- 服务器异步响应处理。
- 服务器反应代码。
我的问题是:为什么我不能使用 jax-rs 端点创建非阻塞代码并利用标准事件循环线程?
编辑:
有几个问题困扰着我:
Resteasy is not async by default, but it is capable of handling non blocking async response
async by default
和is capable of handling non blocking async response
有什么区别?- 从这里,我发现任何 JAX-RS 实现都能够处理非阻塞异步响应,因为
@Suspended
是一个 JAX-RS 注释,不是吗?
我认为 this article 很好地解释了这些概念的含义。
编辑 2:
另一边,根据Quarkus Http documentation,它说:
All the HTTP requests your application receive are handled by event loops (IO Thread) and then are routed towards the code that manages the request. Depending on the destination, it can invoke the code managing the request on a worker thread (Servlet, Jax-RS) or use the IO Thread (reactive route).
在这里,我发现默认情况下,所有 JAX-RS "endpoints" 都由 工作线程(工作垂直?) 处理,因为它们是阻塞的默认情况下。
根据 vert.x 文档:
By default blocking code is executed on the Vert.x worker pool.
我现在的问题是:
- 正如我们之前提到的,我们可以使用
AsyncResponse
使 jax-rs "endpoint" 成为非阻塞的。现在当 jax-rs 端点进入阻塞代码时是否必须使用工作线程? - a "quarkus worker thread" 等同于 "vert.x worker verticle"?
JAX-RS 只是一个标准。 Quarkus 使用 RESTEasy 作为 JAX-RS 实现。 RESTEasy 使用阻塞 API:
Resteasy is not async by default, but it is capable of handling non blocking async response, specially with Vert.x
您可以在这里阅读更多相关信息:https://github.com/vert-x3/vertx-examples/tree/master/resteasy-examples
RESTEasy 是 JBoss 的一部分。 JBoss 是 Red Hat 的一部分。 Quarkus 也是一个 Red Hat 项目。
理论上,您可以使用另一个非阻塞的 JAX-RS 实现。但是我什么都不知道,原因很简单——JAX-RS 已经过时了。
像async by default
这样的东西可能意味着很多不同的东西。就 Vert.x 而言,这意味着大多数 API 要么期待回调,要么 return 某种未来(Deferred value
,如果你愿意的话)。
已经确定,is capable of handling non blocking async response
意味着默认情况下,JAX-RS 会阻塞直到值被 returned,但从技术上讲,可以将其包装在一种 deferred value
也。这就是 Vert.x RestEasy 集成的作用。
@Suspended
,或更具体地说,AsyncResponse
是包装这些值的另一种方式,尽管比其他方式更骇人听闻。