public class Reactor extends Object implements org.jooby.Jooby.Module
Reactor is a second-generation Reactive library for building non-blocking applications on the JVM based on the Reactive Streams Specification
Flux and Mono into Deferred API.
...
import org.jooby.reactor.Reactor;
...
{
use(new Reactor());
get("/", req -> Flux.just("reactive programming in jooby!"));
}
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 via reactor() route mapper. If you are a
reactor programmer then you don't need to worry
for learning a new API and semantic. The reactor() route operator deal and take
cares of the Deferred API.
Advanced flux/mono configuration is allowed via function adapters:
...
import org.jooby.reactor.Reactor;
...
{
use(new Reactor()
.withFlux(f -> f.publishOn(Computations.concurrent())
.withMono(m -> m.publishOn(Computations.concurrent()));
get("/flux", req -> Flux...);
get("/mono", req -> Mono...);
}
Here every Flux/Mono from a route handler will publish on the concurrent scheduler.
| Constructor and Description |
|---|
Reactor() |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(org.jooby.Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
static org.jooby.Route.Mapper<Object> |
reactor()
Map a reactor object like
Flux or Mono into a Deferred object. |
static org.jooby.Route.Mapper<Object> |
reactor(Function<reactor.core.publisher.Flux,reactor.core.publisher.Flux> flux,
Function<reactor.core.publisher.Mono,reactor.core.publisher.Mono> mono)
Map a reactor object like
Flux or Mono into a Deferred object. |
Reactor |
withFlux(Function<reactor.core.publisher.Flux,reactor.core.publisher.Flux> adapter) |
Reactor |
withMono(Function<reactor.core.publisher.Mono,reactor.core.publisher.Mono> adapter) |
public Reactor withFlux(Function<reactor.core.publisher.Flux,reactor.core.publisher.Flux> adapter)
public Reactor withMono(Function<reactor.core.publisher.Mono,reactor.core.publisher.Mono> adapter)
public static org.jooby.Route.Mapper<Object> reactor(Function<reactor.core.publisher.Flux,reactor.core.publisher.Flux> flux, Function<reactor.core.publisher.Mono,reactor.core.publisher.Mono> mono)
Flux or Mono into a Deferred object.
...
import org.jooby.reactor.Reactor;
...
{
with(() -> {
get("/lux", req -> Flux...);
get("/mono", req -> Mono...);
}).map(Reactor.reactor(
flux -> flux.publishOn(Computations.concurrent()),
mono -> mono.publishOn(Computations.concurrent()));
}
flux - A flux adapter.mono - A mono adapter.public static org.jooby.Route.Mapper<Object> reactor()
Flux or Mono into a Deferred object.
...
import org.jooby.reactor.Reactor;
...
{
with(() -> {
get("/lux", req -> Flux...);
get("/mono", req -> Mono...);
}).map(Reactor.reactor(
flux -> flux.publishOn(Computations.concurrent()),
mono -> mono.publishOn(Computations.concurrent()));
}
public void configure(org.jooby.Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder)
configure in interface org.jooby.Jooby.ModuleCopyright © 2017. All rights reserved.