reactive server
TRANSCRIPT
![Page 1: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/1.jpg)
S
Reactive ServerScott Ryan
December 2016
![Page 2: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/2.jpg)
Who Am I
Open Source Consultant Server Technologies
Java, Groovy, Spring Big Data
Mongo, Hadoop, Spark, Storm Client
Angular 1 & 2, Javascript, CSS, HTML, DS3
![Page 3: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/3.jpg)
Agenda
The challenge Standard Solutions Future of Java Spring Solutions Implementation Considerations
![Page 4: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/4.jpg)
Characteristics of Reactive
Waiting for a response loses the ability operate in a parallel manner Respond in a timely manner Responsive in the face of failure Responsive under varying workload Leverage asynchronous message passing
![Page 5: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/5.jpg)
Slow from both Ends
Service Layer(Limited Threads)
Clients Resources
![Page 6: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/6.jpg)
Why do I need this?
Scalability Non blocking runtimes few
threads (Netty, Node JS(1))
Non blocking applications
Support slow clients in a non blocking way
Resource Availability and Stability
Function chaining (Callback Hell)
Getting Asynchronous right
Simplicity
Composeable Micro-services
![Page 7: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/7.jpg)
Asynchronous Programming Options
Java Futures Retrieving value is blocking Nested futures builds
callback hell
Java 8 Streams Pull based One time use Fixed length Don’t support latency
Completable Futures Completion stage
Finishes and Ends One result
![Page 8: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/8.jpg)
What is Reactive
Ability to push data from a hot source as it is available Observer pattern extended and done right Observable allows subscribers to register interest Producer can indicate completion Produced can indicate error Back pressure can be applied
![Page 9: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/9.jpg)
Data Publisher
![Page 10: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/10.jpg)
Data Subscriber
![Page 11: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/11.jpg)
Data Subscription
![Page 12: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/12.jpg)
20,000 Foot View
Subscriber
Subscription
Publisher
subscribe(Subscriber)
onSubscribe(Subscription)
![Page 13: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/13.jpg)
Java 9 Interfaces
Java.util.concurrent Flow.Publisher Flow.Subscriber Flow.Processor Flow.Subscription
![Page 14: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/14.jpg)
Flow.Publisher
void subscribe(Flow.Subscriber<? super T> subscriber)
![Page 15: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/15.jpg)
Flow.Subscriber
void onComplete() void onError(Throwable throwable) void onNext(T item) void onSubscribe(Flow.Subscription subscription)
![Page 16: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/16.jpg)
Flow.Processor
Combination of Subscriber and Publisher
![Page 17: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/17.jpg)
Flow.Subscription
void cancel() void request(long n) Nothing happens until request is called Request applies back pressure
![Page 18: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/18.jpg)
Bringing it Together
Subscriber
SubscriptionBack Pressure
Publisher
subscribe(Subscriber)
onSubsrcribe(Subscription)
onComplete()onError(Throwable)
onNext(Item)
cancel()request(n)
![Page 19: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/19.jpg)
S
Simple DemoJava 9 Interfaces
![Page 20: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/20.jpg)
Spring 5/Spring Boot 2
Support for implementation of the Flow interfaces Extensive added support to make them scalable and flexible Mono and Flux are Publishers Subscribers and Subscriptions available Implemented in web reactive (Netty, Undertow, Tomcat) Potentially in Spring Data, Spring Security, etc. Oracle reactive drivers
![Page 21: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/21.jpg)
Mono
Implements Publisher Interface Parallels CompletionStage Supports variable latency Produces 0 or 1 result Extensive support for scalability and processing
![Page 22: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/22.jpg)
Flux
Implements Publisher Interface Parallels the Stream implementation Produces multiple results Infinite length possible Supports variable latency Extended for scalability and processing
![Page 23: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/23.jpg)
Potential Ideas
Competing services first one wins Combine results from multiple services
Filter Remove Duplicates
Interleave results from multiple services
![Page 24: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/24.jpg)
MVC Magic
Spring MVC Rest Controllers Compatible with existing Controllers Spring Functional Interface Async input and output
![Page 25: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/25.jpg)
Functional Web Framework
Lightweight Functional definition Perfect for micro service standup
![Page 26: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/26.jpg)
S
Spring MVC DemoReactive 1
![Page 27: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/27.jpg)
High NumberService
PersonService
PersonController
Person Database
Low NumberService(Slow)
![Page 28: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/28.jpg)
S
Spring Functional Demo
Reactive 2
![Page 29: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/29.jpg)
Mongo
Netty
![Page 30: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/30.jpg)
Debugging and Logging
Always a challenge to debug asynchronous operations
Logging may be deceiving Test frameworks on the way
![Page 31: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/31.jpg)
Client Support
Observables on the client side HTTP 2 and Servlet 3.1 provide a pathway Containers like netty and undertow provide value Angular 2 , React etc. support client side
Observables
![Page 32: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/32.jpg)
Conclusion
Choose wisely grasshopper Do not assume it will produce value or performance
More is not necessarily better Prepare the team It is not your fathers Async world Design with Options Watch system load and usage
![Page 33: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/33.jpg)
Questions
![Page 34: Reactive server](https://reader036.vdocuments.site/reader036/viewer/2022062503/58d002281a28abfc0a8b672d/html5/thumbnails/34.jpg)
Resources
Sample Code (Be nice!) https://github.com/scryan7371/javaflow https://github.com/scryan7371/reactive1 https://github.com/scryan7371/reactive2