Reactive Programming with Spring
Petru Flueras
Software Architect - Visma Software
@pflueras
Imperative programming
● Imperative programming is a programming paradigm that uses statements
that change a program's state
○ Statements: conditional statements, loop statements, algorithms, control flow
○ You tell the computer how to do things - low level instructions closer to hardware
○ Higher cyclomatic complexity, less cleaner code, more difficult to test
● Real world example: hey waiter, I want to order a salad, but if the cheese is
too salted then please don’t add olives. Instead you could add more corn!
Declarative programming
● Is a programming paradigm that expresses the logic of a computation without
describing its control flow
○ Less direct control, without going into implementation details!
○ Tell the computer what to do, without specifying how!
○ You create expressions instead of statements + evaluate functions
● Real world example: Hey waiter, I want to order a slightly salted salad!
Exercise 1: Imperative & Declarative
Exercise 1: Imperative
Exercise 2: Declarative
Reactive programming
● Declarative event-based
● Subset of asynchronous programming where the availability of new
information drives the logic forward rather than having control flow driven by a
thread-of-execution
● It supports decomposing the problem into multiple discrete steps where
each can be executed in an asynchronous and non-blocking fashion, and
then be composed to produce a workflow (~ data streams)
● Contention is the biggest enemy of scalability. Reactive program should
rarely, if ever, have to block
Reactive manifesto
Reactive systems are:
● Responsive
● Resilient
● Elastic
● Message Driven
https://www.reactivemanifesto.org/
Reactive Streams + Spring
● Reactive Streams Specification
○ Publisher + Subscriber
○ http://www.reactive-streams.org/
○ JDK 9!
● Project Reactor (Reactive Streams implementation)
○ Flux<T>, Mono<T>
● Spring WebFlux
○ ReactiveCrudRepository, ReactiveMongoRepository, ReactiveRedis*, RouterFunction, …
DEMO!
Spring MVC
Spring WebFlux
Thank you!

Reactive Programming with Spring

  • 1.
    Reactive Programming withSpring Petru Flueras Software Architect - Visma Software @pflueras
  • 2.
    Imperative programming ● Imperativeprogramming is a programming paradigm that uses statements that change a program's state ○ Statements: conditional statements, loop statements, algorithms, control flow ○ You tell the computer how to do things - low level instructions closer to hardware ○ Higher cyclomatic complexity, less cleaner code, more difficult to test ● Real world example: hey waiter, I want to order a salad, but if the cheese is too salted then please don’t add olives. Instead you could add more corn!
  • 3.
    Declarative programming ● Isa programming paradigm that expresses the logic of a computation without describing its control flow ○ Less direct control, without going into implementation details! ○ Tell the computer what to do, without specifying how! ○ You create expressions instead of statements + evaluate functions ● Real world example: Hey waiter, I want to order a slightly salted salad!
  • 4.
  • 5.
  • 6.
  • 7.
    Reactive programming ● Declarativeevent-based ● Subset of asynchronous programming where the availability of new information drives the logic forward rather than having control flow driven by a thread-of-execution ● It supports decomposing the problem into multiple discrete steps where each can be executed in an asynchronous and non-blocking fashion, and then be composed to produce a workflow (~ data streams) ● Contention is the biggest enemy of scalability. Reactive program should rarely, if ever, have to block
  • 8.
    Reactive manifesto Reactive systemsare: ● Responsive ● Resilient ● Elastic ● Message Driven https://www.reactivemanifesto.org/
  • 9.
    Reactive Streams +Spring ● Reactive Streams Specification ○ Publisher + Subscriber ○ http://www.reactive-streams.org/ ○ JDK 9! ● Project Reactor (Reactive Streams implementation) ○ Flux<T>, Mono<T> ● Spring WebFlux ○ ReactiveCrudRepository, ReactiveMongoRepository, ReactiveRedis*, RouterFunction, …
  • 10.
  • 11.
  • 12.
  • 13.