Search code examples
spring-bootspring-webfluxproject-reactorhibernate-reactive

Is there compatibility between Uni<> and Reactor's Mono<>?


I'm trying to connect Hibernate Reactive and Spring WebFlux(Project Reactor most). The problem is that Uni<>(Hibernate Reactive type) replaces Mono<> (Reactive type from Project Reactor), and from now, behaviour is not such obviously, as Project Reactor provides without other reactive types.

Is there are some tools for compatibility between Uni<> and Reactor's Mono<>/Flux<>?

Already Investigated GitHub repos, tried to connect reactive types via custom spring starters.


Solution

  • Yes, there is support to convert between the two type systems.

    Add the following dependency...

    <dependency>
        <groupId>io.smallrye.reactive</groupId>
        <artifactId>mutiny-reactor</artifactId>
        <version>1.7.0</version>
    </dependency>
    

    ...and use the following code:

    Mono<T> monoFromUni = uni.convert().with(UniReactorConverters.toMono());
    

    You can find detailed documentation here: https://smallrye.io/smallrye-mutiny/1.7.0/guides/converters/