SlideShare a Scribd company logo
Reactive Programming
for Java Developers
Constantin PopaEngineering #5
16:00-16:45
Reactive Programming
for Java Developers
Constantin Popa
Reactive Programming
for Java Developers
Constantin Popa
First
a
Survey
Who here uses…
Java 8
Spring framework
RxJava/Reactor
Spring WebFlux
AGENDA
Reactive Programming 101
Reactive streams – Project Reactor
Reactive web apps – Spring WebFlux
Reactive Programming 101
Why?
because blocking is evil
sync&blocking
main thread
I/O
time
main thread
resume processing
async&blocking
main thread
time
wait & join
I/O
I/O
async&nonblocking
main thread
time
Event loop
worker thread
I/O request
I/O request
I/O Data
available
how do achieve that?
without losing your mind…
Reactive Programming
“Composing asynchronous &
event-based streams
using non-blocking operators”
We don’t sacrifice much
callbacks?
Future? CompletableFuture?
Pull? Push!
vs
Iterable
-
Iterator
Publisher
-
Subscriber
Data in Flux
Publisher Subscriber
produces consumes
push events
Feedback
interfaces from
Reactive Streams
specification
now part of Java 9, under
java.util.concurrent.Flow
Subscriber<T>
onNext(T)
onComplete()
onError(Throwable)
onSubscribe(Subscription)
0..N elements
+
0..1 (complete | error)
backpressure
These interfaces
don’t do much…
Subscription.request(n)
Subscription.cancel()
Project Reactor
Flux<T>
generates 0..N elements
Marble diagrams
Give the Flux a second chance
Interactive marble diagrams on http://rxmarbles.com
(most map to Reactor operators)
Mono<T>
generates 0..1 elements
Reactive programming for java developers
Reactive streams vs Java 8 streams
”The design center for Streams is mostly about data that can be accessed
with no latency (either from data structures or generating functions)”
“The design center for Rx is about infinite streams of events which
may arrive asynchronously.”
Brian Goetz
an Rx-inspired API
with a vocabulary of operators similar to RxJava
Flux.range map
filter
buffer Subscriber
Nothing happens
until you subscribe
Reactive programming for java developers
Reactive programming for java developers
Reactive programming for java developers
Flux.range(1,3) map
filter
buffer Subscriber
123
Flux.range(1,3)
.map( number -> toShape())
.filter(shape -> isCircle())
.buffer()
.subscribe(shape -> printShape())
More awesomeness
async sub-processes with flatMap
Reactive programming for java developers
Reactor is
concurrency-agnostic
Flux.range(1,3)
.map( number -> toShape())
.filter(shape -> isCircle())
.buffer()
.subscribe(shape -> printShape())
Flux.range(1,3)
.subscribeOn(Schedulers.elastic())
.map(number -> toShape())
.filter(shape -> isCircle())
.buffer()
.publishOn(Schedulers.immediate())
.subscribe(shape -> printShape())
Schedulers.single()
Schedulers.parallel()
Schedulers.elastic()
Schedulers.immediate()
Reactive web applications Spring
WebFlux
Use case #1
Reactive data repository
Let's recap:
HTTP GET with reactive data repository
Designed to work with both Spring MVC and Spring WebFlux
Simply return reactive types(Flux, Observable) from @Controller
@GetMapping("/cars")
@ResponseBody
public Flux<Car> getCars() {
return this.repository.findAll();
}
Flux<T>:
finite collection or infinite stream?
Use media type to decide
“application/json”
finite collection(JSON array)
“text/event-stream”
“application/stream+json”
infinite stream
DEMO
Use case #2
Response stream with backpressure
Handling backpressure
request(n)->write->flush->repeat
DEMO
Let’s recap:
HTTP GET with streaming response
Simply return reactive types(Flux, Observable) from @Controller
Backpressure handling on both Spring MVC and Spring WebFlux
Use case #3
Reactive remote service orchestration
DEMO
Let’s recap:
Reactive webclient
Orchestrate non-blocking, nested remote service calls with ease.
Similar to reactive data access
Reactive programming for java developers
Reactive programming for java developers
What WebFlux is good for:
High traffic
High concurrency with less hardware resources
Latency, streaming scenarios
Summary
Quite a steep learning curve
Doesn’t fit all scenarios, if it ain’t broken, don’t fix it
It’s fun time to be a Java developer!
Spring WebFlux and Reactor unlock the gates for easy Reactive
Programming on the server side and not only

More Related Content

What's hot (20)

PDF
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 
PPTX
Flink Forward SF 2017: Stephan Ewen - Convergence of real-time analytics and ...
Flink Forward
 
PDF
Flink Forward SF 2017: Joe Olson - Using Flink and Queryable State to Buffer ...
Flink Forward
 
PDF
Explore your prometheus data in grafana - Promcon 2018
Grafana Labs
 
PDF
How I learned to time travel, or, data pipelining and scheduling with Airflow
Laura Lorenz
 
PPTX
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
PPTX
Apache Flink Training: System Overview
Flink Forward
 
PDF
OASGraph LoopBack 4 Integration
Mario Estrada
 
PDF
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward
 
PPTX
Reactive
Pranav E K
 
PPT
EUROCONTROL LARA - Presentation
SalvatoreBI
 
ODP
Introduction to Akka Streams [Part-II]
Knoldus Inc.
 
ODP
Understanding Spark Structured Streaming
Knoldus Inc.
 
ODP
Introduction to Akka Streams [Part-I]
Knoldus Inc.
 
PDF
Flink Forward SF 2017: Chinmay Soman - Real Time Analytics in the real World ...
Flink Forward
 
PDF
Effective java item 80 and 81
Isaac Liao
 
PPTX
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
Flink Forward
 
PPTX
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward
 
PPTX
Apache Flink Berlin Meetup May 2016
Stephan Ewen
 
PPTX
Enhancements in Java 9 Streams
Corneil du Plessis
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 
Flink Forward SF 2017: Stephan Ewen - Convergence of real-time analytics and ...
Flink Forward
 
Flink Forward SF 2017: Joe Olson - Using Flink and Queryable State to Buffer ...
Flink Forward
 
Explore your prometheus data in grafana - Promcon 2018
Grafana Labs
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
Laura Lorenz
 
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
Apache Flink Training: System Overview
Flink Forward
 
OASGraph LoopBack 4 Integration
Mario Estrada
 
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward
 
Reactive
Pranav E K
 
EUROCONTROL LARA - Presentation
SalvatoreBI
 
Introduction to Akka Streams [Part-II]
Knoldus Inc.
 
Understanding Spark Structured Streaming
Knoldus Inc.
 
Introduction to Akka Streams [Part-I]
Knoldus Inc.
 
Flink Forward SF 2017: Chinmay Soman - Real Time Analytics in the real World ...
Flink Forward
 
Effective java item 80 and 81
Isaac Liao
 
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
Flink Forward
 
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward
 
Apache Flink Berlin Meetup May 2016
Stephan Ewen
 
Enhancements in Java 9 Streams
Corneil du Plessis
 

Similar to Reactive programming for java developers (20)

PDF
Guide to Spring Reactive Programming using WebFlux
Inexture Solutions
 
PDF
Reactive Applications in Java
Alexander Mrynskyi
 
PPTX
Reactive programming with Spring Webflux.pptx
João Esperancinha
 
PPTX
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Scrum Breakfast Vietnam
 
PDF
Reactive programming with spring web flux
Ravindra Ranwala
 
PPTX
Reactive Spring 5
Corneil du Plessis
 
PDF
Introduction to Spring webflux
Knoldus Inc.
 
PDF
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
VMware Tanzu
 
PPTX
From Web to Flux @DevoxxBE 2023.pptx
Victor Rentea
 
PPTX
Reactive programming
SUDIP GHOSH
 
PDF
Building RESTFUL APIs with Spring Webflux
Knoldus Inc.
 
PPTX
Spring webflux
Carlos E. Salazar
 
PDF
NCUG 2019: Super charge your API’s with Reactive streams
Frank van der Linden
 
PDF
Reactor in Action
VMware Tanzu
 
PDF
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
 
PPTX
Going Reactive with Spring 5
Drazen Nikolic
 
PDF
Reactive&amp;reactor
Geng-Dian Huang
 
PDF
Let’s go reactive with JAVA
Tech Triveni
 
PDF
Project Reactor Now and Tomorrow
VMware Tanzu
 
PDF
Spring 5 Project Reactor
Geoffrey Filippi
 
Guide to Spring Reactive Programming using WebFlux
Inexture Solutions
 
Reactive Applications in Java
Alexander Mrynskyi
 
Reactive programming with Spring Webflux.pptx
João Esperancinha
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Scrum Breakfast Vietnam
 
Reactive programming with spring web flux
Ravindra Ranwala
 
Reactive Spring 5
Corneil du Plessis
 
Introduction to Spring webflux
Knoldus Inc.
 
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
VMware Tanzu
 
From Web to Flux @DevoxxBE 2023.pptx
Victor Rentea
 
Reactive programming
SUDIP GHOSH
 
Building RESTFUL APIs with Spring Webflux
Knoldus Inc.
 
Spring webflux
Carlos E. Salazar
 
NCUG 2019: Super charge your API’s with Reactive streams
Frank van der Linden
 
Reactor in Action
VMware Tanzu
 
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
 
Going Reactive with Spring 5
Drazen Nikolic
 
Reactive&amp;reactor
Geng-Dian Huang
 
Let’s go reactive with JAVA
Tech Triveni
 
Project Reactor Now and Tomorrow
VMware Tanzu
 
Spring 5 Project Reactor
Geoffrey Filippi
 
Ad

Recently uploaded (20)

PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Ad

Reactive programming for java developers