Correct way to pass data to reactive Qute with reactive panache. #38577
Replies: 3 comments
-
/cc @FroMage (panache), @loicmathieu (panache), @mkouba (qute) |
Beta Was this translation helpful? Give feedback.
-
You're not breaking the reactive concept when returning an Uni<List>. There's a reference in the documentation explaining exactly that: https://quarkus.io/guides/getting-started-reactive
So when you retrieve a Multi on some JAX-RS endpoint and then take a look at the HTTP response you'll see something like this:
And when returning Uni:
See? When you return a Multi, the response is chunked, therefore it is not returned all at once; instead, it returns the content in multiple parts. I am not sure when we should apply this chunked concept, perhaps when we need to return a large file in a non-blocking fashion or something like that... A more common use case for Multi's would be in situations that you need to handle backpressure and emit a lot of events per second/ms. Also, an equivalent approach of the Uni reponse would be: @GET
@Produces(MediaType.TEXT_HTML)
public Uni<TemplateInstance> get(@QueryParam("name") String name) {
return Uni.createFrom().item(
this.fruit.instance()
.data("name", name)
.data("listFruit", findAllUni())
);
}
public static Uni<List<Fruit>> findAll() {
return this.client.query("SELECT id, name FROM fruits ORDER BY name ASC").execute()
.onItem().transform(rows -> {
List<Fruit> fruits = new ArrayList<>();
RowIterator<Row> iterator = rows.iterator();
do {
Row row = iterator.next();
fruits.add(Fruit.from(row));
} while (iterator.hasNext());
return fruits;
})
;
} |
Beta Was this translation helpful? Give feedback.
-
Using More details can be found in the docs. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building an app using Qute with Panache both reactives.
My qute template has a list where I'm using #for stament to create the rows from the query result.
My repository is returning a Multi<Object> but when I try to pass this to Template data method, I get an error that is not an iterable object, I change it to return Uni<List<Object>> and it works, but is this best/correct way to pass data to Qute, using Uni<List> I'm not breaking the reactive way to link the result query with Template render ?
Example:
Model with some Repository methods
Resource
Template
Dependencies and using Quarkus 3.7.1
Beta Was this translation helpful? Give feedback.
All reactions