liveBook · Manning

Reactive stream

As explained in Spring Security in Action, Second Edition

The Reactive Streams specification defines standard contracts for asynchronous stream processing with bounded resource usage.

Reactive Streams defines standard contracts for asynchronous stream processing with bounded resource usage. A publisher produces values, while a subscriber consumes them. Project Reactor implements these contracts and provides the functional API underlying Spring’s reactive programming model. section 17.1

The implementation model connects these roles:

  • Publisher: the contract for a source of data. section 17.1
  • Mono and Flux: Reactor publishers used to represent reactive data sources. section 17.1
  • Subscriber: the consumer receiving values from a publisher. section 17.1

Reactive endpoint

A Spring WebFlux controller can return Mono<String> from an endpoint, producing a single reactive value with Mono.just("Hello!"). section 17.1

Figure 17.1 Non-reactive vs. reactive. In a non-reactive approach, the milk factory gets all the milk to be packaged in the morning and delivers all the boxes in the evening. In a reactive approach, as the milk is brought to the factory, it’s packaged and then delivered. For this scenario, a reactive approach is better as it allows milk to be collected throughout the day and delivered sooner to the clients.

Compare reactive processing with batch-style processing through the factory analogy: values are processed and delivered as they arrive rather than after the complete input is collected. section 17.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains publisher and subscriber contracts and connects them to Mono, Flux, and Project Reactor.
Examples
Uses a Spring WebFlux HelloController returning Mono<String> and a factory analogy contrasting reactive and non-reactive processing.
What you can do after
Apply it via Project Reactor by modeling endpoint results with Mono or Flux publishers.
How it connects
Connects asynchronous stream processing with publishers, subscribers, Project Reactor, Mono, Flux, and Spring WebFlux.

Also explained in

Compare how 4 books explain reactive stream →

Related concepts

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