Jordi
Jordi

Reputation: 23237

quarkus jaxrs non-blocking misconception

As far I've been able reading:

Probably misconceptions: what exactly do following terms mean?

My question is: why ain't I able to create non-blocking code using jax-rs endpoints and leverage standard event-loop thread?

EDIT:

A couple of question are strugling my mind:

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

  1. Which is the difference between async by default, and is capable of handling non blocking async response?
  2. From here, I figure out any JAX-RS implementation is able to handle non blocking async response, since @Suspended is a JAX-RS annotation, doesn't it?

I think this article explains very well what those concepts are meant for.

EDIT 2:

By other side, according to Quarkus Http documentation, it says:

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).

Form here, I figure out that, by default, all JAX-RS "endpoints" are handled by a worker thread (worker verticle?) since they are blocking by default.

According to vert.x documentation:

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

My questions now are:

  1. As we have mentioned before, we are able to make a jax-rs "endpoint" non-blocking using an AsyncResponse. Is it mandatory to use a worker thread when the jax-rs endpoint in to a blocking code now?
  2. a "quarkus worker thread" is equivalent to "vert.x worker verticle"?

Upvotes: 3

Views: 1905

Answers (1)

Alexey Soshin
Alexey Soshin

Reputation: 17711

JAX-RS is just a standard. Quarkus uses RESTEasy as JAX-RS implementation. RESTEasy uses blocking API:

Resteasy is not async by default, but it is capable of handling non blocking async response, specially with Vert.x

You can read more about it here: https://github.com/vert-x3/vertx-examples/tree/master/resteasy-examples

RESTEasy is part of JBoss. JBoss is part of Red Hat. Quarkus is also a Red Hat Project.

Theoretically, you could use another JAX-RS implementation that is non blocking. But then I'm not aware of any, for one simple reason - JAX-RS is quite outdated.

Things like async by default may mean a lot of different things. In terms of Vert.x, it means that most of the APIs are either expect a callback or return some kind of Future (Deferred value, if you please).

Having established that, is capable of handling non blocking async response means that by default, JAX-RS blocks until the value is returned, but technically, it's possible to wrap this in a kind of deferred value too. That's what Vert.x RestEasy integration does.

@Suspended, or more specifically, AsyncResponse, is another way to wrap those values, although much hackier one than some others.

Upvotes: 2

Related Questions