liveBook · Manning

Reactive application

As explained in Spring Security in Action, Second Edition

A reactive application is an application designed around asynchronous, nonblocking processing of streams of data and events.

A reactive application processes data and events asynchronously in fragments rather than waiting for an entire task or request payload. This approach can deliver processed results sooner and address limitations of imperative programming, but it is not the best fit for every situation. section 17.0 section 17.1

A reactive design typically involves these behaviors:

  • Receive and process data as it arrives instead of waiting for all data to become available. section 17.1
  • Divide large tasks into subtasks that can be approached simultaneously. section 17.0
  • Represent streams through publishers that produce values and subscribers that consume them under Reactive Streams contracts. section 17.1
  • Avoid storing authentication details at thread level because one request's tasks may run on multiple threads. section 17.1

Spring WebFlux endpoint

A Spring reactive controller can return Mono<String> from a /hello endpoint, producing the response through a reactive type rather than an ordinary immediate value. A reactive OAuth 2 resource server can secure the same style of endpoint with SecurityWebFilterChain, oauth2ResourceServer(), jwt(), and a configured JWK set URI. section 17.1 section 17.4

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 batch-style imperative processing with reactive processing through a milk-factory analogy: reactive delivery begins as input arrives instead of waiting for the full batch. section 17.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Reviews core processing and threading behavior, then applies Spring Security configuration without developing reactive programming in full detail.
Examples
Uses file uploads, a milk factory, a Mono-based HelloController, and a JWT-protected reactive resource server.
What it assumes
Explains reactive essentials before deeper Spring Security configuration and defers detailed reactive application study to other material.
What you can do after
Build it from scratch with Spring WebFlux and secure it through a reactive SecurityWebFilterChain configured for OAuth 2 JWT validation.
How it connects
Connects reactive programming with imperative programming, Reactive Streams, Project Reactor, Spring Security, OAuth 2, and JWT.

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.