-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hibernate reactive routes quickstart improvements #626
Hibernate reactive routes quickstart improvements #626
Conversation
- based on the latest reactive routes API improvements
CC @DavideD |
I just merged quarkusio/quarkus#10871. |
public Multi<Fruit> getAll(RoutingContext rc) throws Exception { | ||
return session.createNamedQuery(Fruit.FIND_ALL, Fruit.class).getResults(); | ||
public Multi<Fruit> getAll() throws Exception { | ||
return ReactiveRoutes.asJsonArray(session.createNamedQuery(Fruit.FIND_ALL, Fruit.class).getResults()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ReactiveRoutes.asJsonArray(
required now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it was required even before but the test does not validate the proper syntax of json array...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it required (For now) to creates an asynchronous json array. Each item is written in the response when ready (and sent to the client).
We are improving this by inferring this from the produces
attribute. But it's WIP...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It surprised me because when I write
@Route(methods = GET, path = "/")
public Uni<List<Fruit>> getAll(RoutingContext rc) throws Exception {
return session.createNamedQuery( Fruit.FIND_ALL, Fruit.class).getResultList();
}
It works as expected. I'm wondering if it wouldn't look better to return a Uni<List>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it looks better, but the quickstart is supposed to teach to people "the right way".
@cescoffier are you optimistic about your WIP to be doable? If so, maybe it's ok for the example to already show the simpler syntax? We're not working to win a benchmark war yet ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P.S. I see that the alternative API which I referred to - one which produces a "real Multi" - isn't around yet, but I expect we'll be able to make one based on the scrollable API of ORM - wich is backed by server side cursors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use what looks best then.
Uni<List<Fruit>>
then? ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Hibernate Reactive does not support this yet" does not sound good
I don't think this is a Hibernate Reactive issue, it's a general issue when designing the API. Not saying that we need to add a comment but something similar to this would tell the user the differences:
In this case it makes sense to return a Uni<List<Fruit>> because we return a reasonable amount of results.
Consider returning a Multi<Fruit> for streaming results (link to example).
The example doesn't even have to be a Hibernate Reactive one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For everybody interested, this is the issue explaining why Hibernate Reactive hasn't a proper Multi return method: hibernate/hibernate-reactive#153
Having some feedback is always nice.
By the way, does the quickstart work when you go to http://localhost:8080/index.html?
I forgot to test the web page and it doens't seem to work without it. Any idea why? |
It would be weird that you would need any RESTEasy dependency when going full reactive routes. But I'll let Martin answer. CI is failing with:
so there's something wrong going on. |
By removing the json dependency it removes the reasteasy extension and the index page is not served anymore. |
You need RESTEasy to server static resources even when using Reactive routes? |
I believe so, maybe not. I can't remember if we moved to the Vert.x Static file handler or if it's still the Resteasy feature that is used. |
@gsmet That's very likely a failure related to quarkusio/quarkus#10871. It should be fixed now. @DavideD @gsmet @cescoffier For resteasy standalone we register a wrapped |
@mkouba Yes, we should move this to vertx-http. @stuartwdouglas What's your opinion on this? |
Out of curiosity, what's the difference between |
|
I see, thanks |
Sounds reasonable. |
14bb2c8
to
7365c7b
Compare
The CI failure is probably unrelated:
|
@DavideD The CI is green now! Feel free to merge this PR ;-). |
I don't think he can :). Let me know if it's ready to go in, I will merge it. |
Ah, you're right. So I think it's ready but maybe one more +1 would be good ;-). |
.continueWith(httpResponse(rc, 404)); | ||
public Uni<Fruit> update(@Body Fruit fruit, @Param String id) { | ||
if (fruit == null || fruit.getName() == null) { | ||
return Uni.createFrom().failure(new IllegalArgumentException("Fruit name was not set on request.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A curiosity, does it have to be a Uni in this case? Can't we just throw the exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can. But I think that it's better to avoid throwing an exception unless we have to...
It's OK for me to merge it (somebody else needs to do ti though) but without the additional dependency going to http://localhost:8080/index.html is not going to work (unless something has changed already). We should also add a test that checks that the page is up and running so that we won't forget about it in the future. |
This is already fixed in master... |
Awesome! |
Merging then, thanks everyone! |
quarkusio/quarkus#10871 must be merged first...