reactor

reactor

Reactor is a second-generation Reactive library for building non-blocking applications on the JVM based on the Reactive Streams Specification

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-reactor</artifactId>
 <version>1.6.6</version>
</dependency>

exports

  • map route operator that converts Flux and Mono into Deferred API.

usage

...
import org.jooby.reactor.Reactor;
...
{
  use(new Reactor());

  get("/", () -> Flux.just("reactive programming in jooby!"));
}

how it works?

Previous example is translated to:

{
  use(new Reactor());

  get("/", req -> {
   return new Deferred(deferred -> {
     Flux.just("reactive programming in jooby!")
       .consume(deferred::resolve, deferred::reject);
   });
  });

}

Translation is done with the Reactor.reactor() route operator. If you are a reactor programmer then you don’t need to worry for learning a new API and semantic. The Reactor.reactor() route operator deal and take cares of the Deferred API.

reactor mapper

Advanced flux/mono configuration is allowed via function adapters:

...
import org.jooby.reactor.Reactor;
...
{
  use(new Reactor()
    .withFlux(flux -> flux.pusblishOn(Computations.concurrent())
    .withMono(mono -> mono.pusblishOn(Computations.concurrent()));

  get("/flux", () -> Flux...);

  get("/mono", () -> Mono...);

}

Here every Flux/Mono from a route handler will publish on the concurrent scheduler.