gpt4 book ai didi

java - quarkus jaxrs 非阻塞误解

转载 作者:行者123 更新时间:2023-11-30 01:42:08 24 4
gpt4 key购买 nike

据我所知:

可能存在误解:以下术语到底意味着什么?

  • 服务器非阻塞代码。
  • 服务器异步响应处理。
  • 服务器响应式(Reactive)代码。

我的问题是:为什么我无法使用 jax-rs 端点创建非阻塞代码并利用标准事件循环线程?

编辑:

有几个问题困扰着我:

Resteasy is not async by default, but it is capable of handling non blocking async response

  1. 默认异步能够处理非阻塞异步响应之间有什么区别?
  2. 从这里,我发现任何 JAX-RS 实现都能够处理非阻塞异步响应,因为 @Suspished 是一个 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“端点”都是由 工作线程(worker verticle?) 处理的,因为它们默认是阻塞的。

根据 vert.x 文档:

By default blocking code is executed on the Vert.x worker pool.

我现在的问题是:

  • 正如我们之前提到的,我们可以使用 AsyncResponse 使 jax-rs“端点”成为非阻塞的。当 jax-rs 端点现在进入阻塞代码时,是否强制使用工作线程?
  • “quarkus 工作线程”相当于“vert.x 工作线程”?
  • 最佳答案

    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 是红帽的一部分。 Quarkus 也是红帽项目。

    理论上,您可以使用另一个非阻塞的 JAX-RS 实现。但我不知道有什么,原因很简单 - JAX-RS 已经过时了。

    默认异步这样的东西可能意味着很多不同的事情。就 Vert.x 而言,这意味着大多数 API 要么期望回​​调,要么返回某种 Future(延迟值,如果您愿意的话)。

    已经确定,能够处理非阻塞异步响应意味着默认情况下,JAX-RS 会阻塞直到返回值,但从技术上讲,可以将其包装在一种 递延值也是如此。这就是 Vert.x RestEasy 集成的作用。

    @Suspished,或更具体地说,AsyncResponse,是包装这些值的另一种方式,尽管比其他方式更黑客。

    关于java - quarkus jaxrs 非阻塞误解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59583615/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com