liveBook · Manning

Project Reactor

As explained in Spring in Action, Sixth Edition

Project Reactor is a Java library that provides reactive types and operators for asynchronous, nonblocking stream processing.

Project Reactor is a Java library for composing reactive data pipelines. Instead of waiting for an entire batch before passing it on, a pipeline can pass along data as it becomes available—like newspapers delivered each day rather than all at year’s end. Its operations may run on the same thread or different threads; a pipeline does not guarantee either. section 11.0 section 11.2

Reactor implements Reactive Streams and supplies a functional API for joining its parts: a Publisher emits data, a Subscriber receives it, and a Processor can receive data and publish results. This model underpins Spring’s reactive programming model. section 11.1.1

Start with Reactor’s two Publisher types:

  • Flux represents zero, one, or many items, potentially without an end. section 11.2
  • Mono is optimized for no more than one item. section 11.2
Mono.just("Craig")
    .map(n -> n.toUpperCase())
    .map(cn -> "Hello, " + cn + "!")
    .subscribe(System.out::println);

A greeting pipeline starts with Mono.just(), transforms the value with two map() calls, and prints the result through subscribe(). Each transformation produces another Mono. section 11.2

To try a pipeline in a Spring Boot project, add reactor-core to the build; add reactor-test for tests. Spring Boot manages their versions. Outside Spring Boot, configure Reactor’s BOM for dependency management. section 11.2.2

<dependency>
  <groupId>io.projectreactor</groupId>
  <artifactId>reactor-core</artifactId>
</dependency>

This Maven dependency adds the Reactor library needed for Mono and Flux pipelines. section 11.2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines the Reactive Streams contracts and Mono and Flux, then works through just(), map(), and subscribe() without prescribing a thread.
Examples
Contrasts an imperative greeting with a Mono greeting pipeline and supplies Maven dependencies for reactor-core and reactor-test.
What it assumes
Assumes a Java project build while introducing Reactive Streams contracts and Mono and Flux from their basic roles.
What you can do after
Applies Project Reactor to compose a Mono pipeline using just(), map(), and subscribe().
How it connects
Connects Reactive Streams, Publisher, Subscriber, Processor, Mono, Flux, and Spring’s reactive programming model.

Also explained in

Compare how 2 books explain Project Reactor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.