Skip to content
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

Vert.X hibernate reactive stage setup example #846

Closed
arifpratama398 opened this issue Jun 7, 2021 · 10 comments
Closed

Vert.X hibernate reactive stage setup example #846

arifpratama398 opened this issue Jun 7, 2021 · 10 comments
Labels
question Further information is requested

Comments

@arifpratama398
Copy link

Hello guys, can you tell me where i can get example to setup vertx web with hibernate-reactive using Stage mode ?

I just could found this example which using Mutiny :
https://how-to.vertx.io/hibernate-reactive-howto/

Thanks in advance.

@DavideD
Copy link
Member

DavideD commented Jun 8, 2021

I don't think there is one at the moment.

As far as the Hibernate Reactive session factory, you can get one that uses the Stage mode via:

  emf = Persistence
    .createEntityManagerFactory("pg-demo", props)
    .unwrap(Stage.SessionFactory.class);

You can then convert a Uni to a CompletionStage (and vice-versa) with:

Uni uni = ...
CompletionStage stage = uni.subscribeAsCompletionStage();
Uni uni =Uni.createFrom().completionStage( stage );

Out of curiosity, why do you want to use the Stage mode?

@DavideD DavideD added the question Further information is requested label Jun 8, 2021
@arifpratama398
Copy link
Author

Thanks for the explanation,
previously I thought of using stage mode and vertx to reduce third party dependencies,
besides I'm not familiar with mutiny, and I had some doubts to use this library. Is it stable and have good community for discussion?

Iam sorry for opening insignificant case in issue, next time i will use forums instead.

@DavideD
Copy link
Member

DavideD commented Jun 9, 2021

Yes, Mutiny is pretty stable. and they usually answer to question quite quickly You can find the website with all the details about the community here: https://smallrye.io/smallrye-mutiny/

Anyway, there's nothing wrong in using the CompletionStage API, I just find the Mutiny helps you write cleaner code.
I will try to create an example that uses CompletionStage this week but, in the meanwhile, you can try to convert it using this table in the Hibernate Reactive docs: http://hibernate.org/reactive/documentation/1.0/reference/html_single/#_apis_for_chaining_reactive_operations

No need to be sorry, we like the feedback :-)

@gavinking
Copy link
Member

I'm not sure there's a really strong need for a separate example showing Vert.x and CompletionStage, simply because the examples would be so similar. And I agree that Mutiny is a much more comfortable API for use with HR. But I guess if you want to do it, it's probably not much work. I don't think I would bother.

@DavideD
Copy link
Member

DavideD commented Jun 11, 2021

I've created this JBang alias of the example that doesn't use Mutiny: https://github.com/DavideD/jbang-rep/blob/main/StageVerticle.java

Once you have installed JBang, you can run it with:

jbang stage-verticle@DavideD/jbang-rep

And you can open it in your ide (IDEA for example) with:

jbang edit --open  stage-verticle@DavideD/jbang-rep

(Even if you are not familiar with JBang, as long as you copy this class in a new project and add the dependencies at the top, it will work).

Anyway, it should give you an idea on how to use Future and CompletionStage.
But I still think you should give Mutiny a go.

Cheers.

@DavideD
Copy link
Member

DavideD commented Jun 11, 2021

I'm closing this issue but let me know if you have further questions.

@DavideD DavideD closed this as completed Jun 11, 2021
@arifpratama398
Copy link
Author

Thanks to @DavideD and @gavinking, I have read and tried the example you gave, and it works. Sure i will try to use Mutiny, i just found out it provides some developer experiences than Stage API, i think. It's just that sometimes I have to be bound by policy to choose Stage or Mutiny.

Regards

@DavideD
Copy link
Member

DavideD commented Jun 11, 2021

@arifpratama398 I've noticed a couple of errors in the example. I wasn't completing all the promises and I was creating the factory twice. I've updated it. If you are using jbang, make sure to run it with jbang --fresh stage-verticle@DavideD/jbang-rep .

Also, the original example never closes the factory, but I've added it to the stop method.
@gavinking There should be a factory close when the verticle is stopped, isn't it?

@gavinking
Copy link
Member

Probably.

@DavideD
Copy link
Member

DavideD commented Jun 11, 2021

I suppose that in this case it doesn't make any difference, but it's something to keep in mind for real applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants