liveBook · Manning

Reactive programming

As explained in Spring Security in Action, Second Edition

Reactive programming is a programming paradigm based on asynchronous processing of streams of data and events, typically to support nonblocking and concurrent execution.

Reactive programming processes data and events asynchronously, often by dividing large tasks into subtasks that can progress simultaneously. Clients can receive processed data sooner instead of waiting for an entire task to finish. section 17.0

Reactive applications differ from imperative applications in several practical ways:

  • Process data in fragments as it arrives instead of waiting for the complete dataset. section 17.1
  • Use Reactive Streams as a standard for asynchronous stream processing. section 17.1
  • Use Project Reactor to compose streams through a functional API and provide the foundation for Spring’s reactive programming model. section 17.1
  • Avoid storing authentication details only at thread level because one request’s tasks can run on multiple threads. section 17.1

A minimal reactive endpoint

A Spring WebFlux controller can return a Mono<String> from a /hello endpoint, producing the response through a reactive type rather than returning the string directly. 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 imperative batch processing with reactive processing through a milk-factory analogy: reactive delivery begins as inputs arrive, so clients receive results sooner. section 17.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines incremental processing and demonstrates a Mono endpoint, while deferring detailed reactive application study.
Examples
Uses incremental file uploads, a milk-factory analogy, a Mono-based HelloController, and publisher-subscriber streams.
What you can do after
Build a simple Spring WebFlux endpoint and recognize when reactive processing may improve delivery of fragmented results.
How it connects
Connects asynchronous stream processing with Reactive Streams, Project Reactor, Spring WebFlux, and Spring Security.

Also explained in

Compare how 6 books explain reactive programming →

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.