I created a simple Spring/Vertx integration example application and add Hibernate Reactive to replace the existing Postgres Reactive Client API.
Source codes: https://github.com/hantsy/vertx-sandbox/blob/master/mutiny-spring-hibernate
When running the application and I try to access http://localhost:8888/posts, it is blocked and return nothing, in the background console, the sql is printed.
When I ran the testing codes, it throws an exception, the PostRepository
constructor 0 SessionFactory
bean is not run on the vertx event loop.
@Bean
public Mutiny.SessionFactory sessionFactory() {
return Persistence.createEntityManagerFactory("blogPU")
.unwrap(Mutiny.SessionFactory.class);
}
Updated:, when I changed my handler codes to the following.
this.posts.findAll()
.subscribe()
.with(
data -> {
LOGGER.log(Level.INFO, "posts data: {0}", data);
rc.response().endAndAwait(Json.encode(data));
},
rc::fail
);
Here, use endAndAwait
instead of the original end
method, it works.
But the test method still failed, due to an empty list returned when accessing the endpoint /posts
.
When I explored the official howto guides: https://github.com/vertx-howtos/hibernate-reactive-howto, which created the SessionFactory
in the Verticle
class to ensure they are run on the same thread.