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.
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?
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.
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 :-)
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.
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.
I'm closing this issue but let me know if you have further questions.
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
@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?
Probably.
I suppose that in this case it doesn't make any difference, but it's something to keep in mind for real applications.