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)

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

Similar to Reactive programming for java developers (20)

Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 
Going Reactive with Relational Databases
Going Reactive with Relational Databases
Ivaylo Pashov
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
Trayan Iliev
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
Trayan Iliev
 
Functional reactive programming
Functional reactive programming
Araf Karsh Hamid
 
Reactive java programming for the impatient
Reactive java programming for the impatient
Grant Steinfeld
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Rick Hightower
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Rick Hightower
 
Reactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka Streams
Dean Wampler
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Lightbend
 
Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
 
IPT Reactive Java IoT Demo - BGOUG 2018
IPT Reactive Java IoT Demo - BGOUG 2018
Trayan Iliev
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Reactive database access with Slick3
Reactive database access with Slick3
takezoe
 
Reactive in Android and Beyond Rx
Reactive in Android and Beyond Rx
Fabio Tiriticco
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
Konrad Malawski
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2
JollyRogers5
 
The Value of Reactive Design - Stéphane Maldini
The Value of Reactive Design - Stéphane Maldini
VMware Tanzu
 
Streaming all the things with akka streams
Streaming all the things with akka streams
Johan Andrén
 
Guide to Spring Reactive Programming using WebFlux
Guide to Spring Reactive Programming using WebFlux
Inexture Solutions
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 
Going Reactive with Relational Databases
Going Reactive with Relational Databases
Ivaylo Pashov
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
Trayan Iliev
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
Trayan Iliev
 
Functional reactive programming
Functional reactive programming
Araf Karsh Hamid
 
Reactive java programming for the impatient
Reactive java programming for the impatient
Grant Steinfeld
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Rick Hightower
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Rick Hightower
 
Reactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka Streams
Dean Wampler
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Lightbend
 
Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
 
IPT Reactive Java IoT Demo - BGOUG 2018
IPT Reactive Java IoT Demo - BGOUG 2018
Trayan Iliev
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Reactive database access with Slick3
Reactive database access with Slick3
takezoe
 
Reactive in Android and Beyond Rx
Reactive in Android and Beyond Rx
Fabio Tiriticco
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
Konrad Malawski
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2
JollyRogers5
 
The Value of Reactive Design - Stéphane Maldini
The Value of Reactive Design - Stéphane Maldini
VMware Tanzu
 
Streaming all the things with akka streams
Streaming all the things with akka streams
Johan Andrén
 
Guide to Spring Reactive Programming using WebFlux
Guide to Spring Reactive Programming using WebFlux
Inexture Solutions
 
Ad

Recently uploaded (20)

chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Understanding Amplitude Modulation : A Guide
Understanding Amplitude Modulation : A Guide
CircuitDigest
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
NALCO Green Anode Plant,Compositions of CPC,Pitch
NALCO Green Anode Plant,Compositions of CPC,Pitch
arpitprachi123
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
4th International Conference on Computer Science and Information Technology (...
4th International Conference on Computer Science and Information Technology (...
ijait
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
Fundamentals of Digital Design_Class_21st May - Copy.pptx
Fundamentals of Digital Design_Class_21st May - Copy.pptx
drdebarshi1993
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
ravicivil
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Blood bank management system project report.pdf
Blood bank management system project report.pdf
Kamal Acharya
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Understanding Amplitude Modulation : A Guide
Understanding Amplitude Modulation : A Guide
CircuitDigest
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
NALCO Green Anode Plant,Compositions of CPC,Pitch
NALCO Green Anode Plant,Compositions of CPC,Pitch
arpitprachi123
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
4th International Conference on Computer Science and Information Technology (...
4th International Conference on Computer Science and Information Technology (...
ijait
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
Fundamentals of Digital Design_Class_21st May - Copy.pptx
Fundamentals of Digital Design_Class_21st May - Copy.pptx
drdebarshi1993
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
COMPOSITE COLUMN IN STEEL CONCRETE COMPOSITES.ppt
ravicivil
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Blood bank management system project report.pdf
Blood bank management system project report.pdf
Kamal Acharya
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Ad

Reactive programming for java developers