SlideShare a Scribd company logo
SPRINGONE2GX
WASHINGTON, DC
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Web Applications
Stephane Maldini
Rossen Stoyanchev
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
About the Speakers
• Stephane Maldini
• Reactor Project Lead
• Reactive Streams Spec contributor
• Rossen Stoyanchev
• Spring Framework committer
• Spring MVC
• WebSocket messaging (STOMP, SockJS)
2
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3
Why are you here ?
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4
What is Reactive ?
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5
Why Non Blocking Matters ?
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 6
Non Blocking = Faster ?
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7
Non Blocking = Internet Scale ?
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Web App Stack
9
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Servlet 3.0 Async Requests
• Async HTTP requests have been possible since Servlet 3.0
• Essentially: the ability to get off the Servlet container thread
• originated from Jetty continuations, CometD, etc.
• “Live” data in web apps
• e.g. HTTP streaming, long polling
• Reduce burden on server thread pool
• scatter-gather, external REST APIs, etc
10
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
• A bit quirky, Servlet API wasn’t built for async
• Complex to grasp in its entirety + comes with some caveats
• e.g. lack of notification when client goes away
• Spring MVC provides full support for Servlet 3 async requests
• alleviates most concerns
• Effectively async can be introduced into existing applications
• … and ecosystem of libraries !
Servlet 3.0 Async Requests: the bottom line
11
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Servlet 3.1 Non-Blocking I/O
• Read and write without blocking
• Register ReadListener and WriteListener callbacks
• switches to non-blocking mode
• ServletInputStream and ServletOutputStream change behavior
• Must call isReady first before read() or write()
• if connection not ready (slow client), callback is scheduled
12
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Servlet 3.1 Non-Blocking: the bottom line
• Carefully designed + it does provide non-blocking capability
• However not easy to use correctly, a number of pitfalls
• Many “innocent” looking parts of Servlet API may lead to blocking
• e.g. request.getParameters()
• For a good overview and perspective see Greg Wilkins’ talk
• ”Into the Wild with Servlet 3.1 Async I/O”
13
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Streams Spec for the JVM
• Specification for non-blocking library interop
• governs exchange of data across async boundaries
• Collaborative effort
• Kaazing, Netflix, Pivotal, RedHat, Twiiter, Typesafe
• Momentum and growing ecosystem of libraries
• network, database, etc.
• On path to adoption in JDK 9 java.util.concurrent
14
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15
onSubscribe
onNext*
(onError|onComplete)?
Publisher
Subscriber
Subscription
Reactive Streams API
request(n)
cancel()
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Back-Pressure
• A key part of Reactive Streams is back-pressure
• It’s a type of flow control
• Subscribers make requests for additional data
• Publishers abide and produce what has been requested
16
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Streams for Network I/O
public interface ServerHttpRequest extends HttpRequest {
Publisher<byte[]> getBody();
}
public interface ServerHttpResponse extends HttpMessage {
Publisher<Void> writeWith(Publisher<byte[]> publisher);
}
17
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Instead of...
public interface ServerHttpRequest extends HttpRequest {
InputStream getBody();
}
public interface ServerHttpResponse extends HttpMessage {
OutputStream getBody();
}
18
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Streams over Servlet Runtime ?
• Servlet 3.1 provides the non-blocking capability
• Reactive Streams provides a non-blocking API with broad industry support
• A single Reactive Streams pipeline
• back-pressure through the layers (from DB to Web server)
• Jetty is actively investigating this very option
19
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Streams and Servlet 4.0 ???
• It is under discussion in the expert group
• It would be great if it did happen
• Potential obstacle is the Java EE 8 - JDK 8 association
• Hopefully not a show-stopper since Reactive Streams is here today
20
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
• Netty was designed from the ground up to be non-blocking
• Easy to translate to Reactive Streams semantics
• Two ongoing experiments
• RxNetty
• Reactor Net
Reactive Streams Over Netty
21
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Streams Network I/O
Akka HTTP, Vert.x, Ratpack, Reactor Net, RxNetty*
22
*(via RxJava-ReactiveStreams bridge)
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 23
Netty, Servlet 3.1
Reactive Streams
Reactive
Web App Stack
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24
Web Framework
Netty, Servlet 3.1
Reactive Streams
Reactive
Web App Stack
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25
Web Framework
Application
Netty, Servlet 3.1
Reactive Streams
Reactive
Web App Stack
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 26
Web Framework
Application
Netty, Servlet 3.1
Reactive Streams
Reactive
Streams
HTTP
Data
Broker
Reactive
Web App Stack
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
?
27
Web Framework
Application
Netty, Servlet 3.1
Reactive Streams
Reactive
Streams
HTTP
Data
Broker
?
API to compose
asynchronous
streams?
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Working with Streams
• Non-blocking services return Publisher<T> instead of <T>
• How do you attach further processing?
• Reactive Streams is a callback-based API
• becomes very nested quickly
• Need something more declarative
• it’s beyond the scope of Reactive Streams
28
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
• Publisher represents a stream of data
• It’s natural to apply operations functional-style
• like the Java 8 Stream
• Need API for composing async logic
• rise above callbacks
Stream Operations
29
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactor Stream
• Project Reactor provides a Stream API
• Reactive Streams Publisher + composable operations
30
Streams.just('a' 'b' 'c')
.take(2)
.map(Character::toUpperCase)
.consume(System.out::println);
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Extensions (Rx)
• Stream composition API based on Observer pattern
• originated at Microsoft, work by Erik Meijer
• Implemented for different languages -- RxJava, RxJS, Rx.NET, …
31
Observable.just('a', 'b', 'c')
.take(2)
.map(Character::toUpperCase)
.subscribe(System.out::println);
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
RxJava and Reactive Streams
• RxJava 1.x predates Reactive Streams and doesn’t implement it directly
• Very similar concepts, different names
• Observable-Observer vs Publisher-Subscriber
• RxJava supports “reactive pull” back-pressure
• RxJava 1.x - Reactive Streams bridge
32
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Demo:
HeadFirst
33
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
RxNetty
• RxJava as the reactive bridge to Netty IO operations
• Immediate and embedded client/server for TCP and HTTP
• Decorating IO Read with rx.Observable and applying dynamic pull/push
• Decorating IO Write with rx.Subscriber and requesting more on flush
34
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
RxNetty … what’s up
• RxNetty has introduced Backpressure support in 0.5
• Powered by the backpressure protocol from RxJava
• Overall the API has been heavily lifted too
https://github.com/ReactiveX/RxNetty/wiki/0.5.x-FAQs
35
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactor Net
36
• Reactive Streams as the reactive bridge to Netty and ZeroMQ IO operations
• Immediate and embedded client/server for TCP, UDP and HTTP
• Decorating IO Read with Publisher and applying dynamic pull/push
• Decorating IO Write with Subscriber and requesting more on flush
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Member of the Reactor initiative
• Reactor is a maturing Reactive Streams suite of libraries
• As with a lot of the reactive libraries, observing a rapidly evolving set of API
• Precluded Reactive Streams specification work
• Now evolving and getting ready for Spring 5 Reactive story
projectreactor.io , github.com/reactor
37
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Demo:
Back-Pressure
38
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Async I/O with Reactive Streams
• Never block on Applications Queues :
Max(request) == Queue.capacity()
• Keep Reading : Any asynchronous handoff is non-blocking
• Make Writes Quicker : IO operation signals demand on availability
• Optimize hardware resources : Claim bounded memory and cpu
39
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Read
One read implementation : Publisher stop-read
• Consume NIO Buffers only when requested
• request size is != bytes read
• Application stopping reads propagates back-pressure
• server buffers fill
• client buffers fill
• eventually throttles client
40
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reactive Write
One write implementation : Subscriber request after flush
• Request after flush indicates availability in write buffer
• Request size is != bytes written
• Write buffers filling naturally propagates back-pressure
• buffers fill
• no requests
• eventually throttles application
41
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Serialization Concerns
• Subscription.request(n)is not absolute ( != bytes number )
• Decoding operations might produce one to many objects
• must match subscriber capacity
• Encoding operations might consume one to many byte chunks
• must match buffering capacity
• Available serialization libraries not built for chunked streams
• Jackson, Kryo, Protobuf, etc.
42
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Demo:
Scatter-gather
43
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring Reactive
44
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring Reactive
• Experimental work for Spring Framework 5
• Non-blocking runtimes -- Netty, Jetty, Tomcat
• Reactive Streams over network I/O -- RxNetty, Reactor Net
• Spring web processing
45
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@RequestMapping("/capitalize")
@ResponseBody
public Publisher<Person> capitalize(@RequestBody Publisher<Person> persons) {
// …
}
46
Reactive Streams Publisher
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@RequestMapping("/capitalize")
@ResponseBody
public Stream<Person> capitalize(@RequestBody Stream<Person> persons) {
return persons.map(person -> {
person.setName(person.getName().toUpperCase());
return person;
});
}
47
Reactor Stream
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@RequestMapping("/capitalize")
@ResponseBody
public Observable<Person> capitalize(@RequestBody Observable<Person> persons) {
return persons.map(person -> {
person.setName(person.getName().toUpperCase());
return person;
});
}
48
RxJava Observable
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
ReactiveX On the Client Side
49
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
RxJS
function() {
StreamService.connect("stream")
.flatMap(unpackCsv)
.subscribe(updateUI, logError, logComplete);
}
var unpackCsv = function (ev) {
return Rx.Observable.from(ev.data ? ev.data.split("n") : [])
.filter(discardEmpty)
.map(csvToJson)
}
50
Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Demo:
RxJS and Ratpack
51
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 52
Learn More. Stay Connected.
@springcentral Spring.io/video
Thank You for Listening!
@smaldini / @rstoya05

More Related Content

PDF
State of Securing Restful APIs s12gx2015
PDF
Intro To Reactive Programming
PDF
Resource Handling in Spring MVC 4.1
PDF
Intro to Reactive Programming
PDF
Reactor 3.0, a reactive foundation for java 8 and Spring
PDF
Introduction to Reactive Streams and Reactor 2.5
PDF
Running Java Applications on Cloud Foundry
PDF
Under the Hood of Reactive Data Access (2/2)
State of Securing Restful APIs s12gx2015
Intro To Reactive Programming
Resource Handling in Spring MVC 4.1
Intro to Reactive Programming
Reactor 3.0, a reactive foundation for java 8 and Spring
Introduction to Reactive Streams and Reactor 2.5
Running Java Applications on Cloud Foundry
Under the Hood of Reactive Data Access (2/2)

What's hot (20)

PPTX
High performance stream processing
PDF
Reactive frontends with RxJS and Angular
PPTX
Building Highly Scalable Spring Applications using In-Memory Data Grids
PDF
Data Migration at Scale with RabbitMQ and Spring Integration
PDF
P to V to C: The Value of Bringing “Everything” to Containers
PPTX
RDBMS and Apache Geode Data Movement: Low Latency ETL Pipeline By Using Cloud...
PDF
Modern messaging with RabbitMQ, Spring Cloud and Reactor
PPTX
Developing rich multimedia applications with Kurento: a tutorial for Java Dev...
PPTX
WebRTC infrastructures in the large (with experiences on real cloud deployments)
PPT
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
PDF
Implementing a WebRTC endpoint in GStreamer: challenges, problems and perspec...
PPT
NUBOMEDIA Webinar
PPTX
Developing rich multimedia applications with FI-WARE.
PDF
Running Spring Boot Applications as GraalVM Native Images
PDF
Implementing Raft in RabbitMQ
PPT
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
PPTX
Kurento: a media server architecture and API for WebRTC
PDF
Developing applications with Kurento
PPTX
Consumer Driven Contracts and Your Microservice Architecture
PPTX
Developing rich multimedia applications with Kurento: a tutorial for JavaScri...
High performance stream processing
Reactive frontends with RxJS and Angular
Building Highly Scalable Spring Applications using In-Memory Data Grids
Data Migration at Scale with RabbitMQ and Spring Integration
P to V to C: The Value of Bringing “Everything” to Containers
RDBMS and Apache Geode Data Movement: Low Latency ETL Pipeline By Using Cloud...
Modern messaging with RabbitMQ, Spring Cloud and Reactor
Developing rich multimedia applications with Kurento: a tutorial for Java Dev...
WebRTC infrastructures in the large (with experiences on real cloud deployments)
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
Implementing a WebRTC endpoint in GStreamer: challenges, problems and perspec...
NUBOMEDIA Webinar
Developing rich multimedia applications with FI-WARE.
Running Spring Boot Applications as GraalVM Native Images
Implementing Raft in RabbitMQ
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
Kurento: a media server architecture and API for WebRTC
Developing applications with Kurento
Consumer Driven Contracts and Your Microservice Architecture
Developing rich multimedia applications with Kurento: a tutorial for JavaScri...
Ad

Viewers also liked (20)

PDF
Reactive Web-Applications @ LambdaDays
PDF
Reactive design: languages, and paradigms
PDF
Reactive Programming in Spring 5
PDF
Reactive Spring Framework 5
PPT
Reactive programming with examples
PDF
Building Evented Single Page Applications
PPTX
Reactive web applications
PDF
Reactive programming
PDF
Reactive Software Systems
PDF
The Reactive Manifesto: Message-driven, Resilient, Elastic, Responsive - Stef...
PPTX
Reactive Systems And Vertx
PDF
Map Reduce in Hazelcast - Hazelcast User Group London Version
PDF
What is Reactive programming?
PDF
Vert.x introduction
PDF
Can Single Page Applications Deliver a World-Class Web UX?
ODP
Node.js architecture (EN)
PDF
Modern app programming with RxJava and Eclipse Vert.x
PDF
Securing Single-Page Applications with OAuth 2.0
PDF
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
PDF
Vert.X like Node.js but polyglot and reactive on JVM
Reactive Web-Applications @ LambdaDays
Reactive design: languages, and paradigms
Reactive Programming in Spring 5
Reactive Spring Framework 5
Reactive programming with examples
Building Evented Single Page Applications
Reactive web applications
Reactive programming
Reactive Software Systems
The Reactive Manifesto: Message-driven, Resilient, Elastic, Responsive - Stef...
Reactive Systems And Vertx
Map Reduce in Hazelcast - Hazelcast User Group London Version
What is Reactive programming?
Vert.x introduction
Can Single Page Applications Deliver a World-Class Web UX?
Node.js architecture (EN)
Modern app programming with RxJava and Eclipse Vert.x
Securing Single-Page Applications with OAuth 2.0
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Vert.X like Node.js but polyglot and reactive on JVM
Ad

Similar to Reactive Web Applications (20)

PPTX
Ratpack - SpringOne2GX 2015
PDF
Spring MVC 4.2: New and Noteworthy
PDF
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
PPTX
Designing, Implementing, and Using Reactive APIs
PPTX
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
PPTX
Developing Real-Time Data Pipelines with Apache Kafka
PDF
Building a Secure App with Google Polymer and Java / Spring
PDF
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
PDF
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
PDF
SpringOnePlatform2017 recap
PDF
Building .NET Microservices
PDF
Cloud-Native Streaming and Event-Driven Microservices
PPTX
Spring Integration Done Bootifully
PPTX
It’s a Multi-Cloud World, But What About The Data?
PPTX
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
PDF
riffing on Knative - Scott Andrews
PPTX
Connecting All Abstractions with Istio
PDF
Migrating to Angular 5 for Spring Developers
PDF
Cloud Native Java with Spring Cloud Services
PDF
The Beginner’s Guide To Spring Cloud
Ratpack - SpringOne2GX 2015
Spring MVC 4.2: New and Noteworthy
Welcome to the Reactive Revolution:RSocket and Spring Cloud Gateway - Spencer...
Designing, Implementing, and Using Reactive APIs
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
Developing Real-Time Data Pipelines with Apache Kafka
Building a Secure App with Google Polymer and Java / Spring
Cloud-Native Streaming Platform: Running Apache Kafka on PKS (Pivotal Contain...
12 Factor, or Cloud Native Apps - What EXACTLY Does that Mean for Spring Deve...
SpringOnePlatform2017 recap
Building .NET Microservices
Cloud-Native Streaming and Event-Driven Microservices
Spring Integration Done Bootifully
It’s a Multi-Cloud World, But What About The Data?
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
riffing on Knative - Scott Andrews
Connecting All Abstractions with Istio
Migrating to Angular 5 for Spring Developers
Cloud Native Java with Spring Cloud Services
The Beginner’s Guide To Spring Cloud

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ai tools demonstartion for schools and inter college
PDF
Nekopoi APK 2025 free lastest update
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Essential Infomation Tech presentation.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
history of c programming in notes for students .pptx
PDF
System and Network Administration Chapter 2
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
L1 - Introduction to python Backend.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
PTS Company Brochure 2025 (1).pdf.......
ai tools demonstartion for schools and inter college
Nekopoi APK 2025 free lastest update
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Operating system designcfffgfgggggggvggggggggg
Essential Infomation Tech presentation.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
history of c programming in notes for students .pptx
System and Network Administration Chapter 2
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo POS Development Services by CandidRoot Solutions
How Creative Agencies Leverage Project Management Software.pdf
Understanding Forklifts - TECH EHS Solution
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Reactive Web Applications

  • 1. SPRINGONE2GX WASHINGTON, DC Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Web Applications Stephane Maldini Rossen Stoyanchev
  • 2. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About the Speakers • Stephane Maldini • Reactor Project Lead • Reactive Streams Spec contributor • Rossen Stoyanchev • Spring Framework committer • Spring MVC • WebSocket messaging (STOMP, SockJS) 2
  • 3. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 Why are you here ?
  • 4. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4 What is Reactive ?
  • 5. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 Why Non Blocking Matters ?
  • 6. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 6 Non Blocking = Faster ?
  • 7. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7 Non Blocking = Internet Scale ?
  • 8. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8
  • 9. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Web App Stack 9
  • 10. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Servlet 3.0 Async Requests • Async HTTP requests have been possible since Servlet 3.0 • Essentially: the ability to get off the Servlet container thread • originated from Jetty continuations, CometD, etc. • “Live” data in web apps • e.g. HTTP streaming, long polling • Reduce burden on server thread pool • scatter-gather, external REST APIs, etc 10
  • 11. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • A bit quirky, Servlet API wasn’t built for async • Complex to grasp in its entirety + comes with some caveats • e.g. lack of notification when client goes away • Spring MVC provides full support for Servlet 3 async requests • alleviates most concerns • Effectively async can be introduced into existing applications • … and ecosystem of libraries ! Servlet 3.0 Async Requests: the bottom line 11
  • 12. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Servlet 3.1 Non-Blocking I/O • Read and write without blocking • Register ReadListener and WriteListener callbacks • switches to non-blocking mode • ServletInputStream and ServletOutputStream change behavior • Must call isReady first before read() or write() • if connection not ready (slow client), callback is scheduled 12
  • 13. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Servlet 3.1 Non-Blocking: the bottom line • Carefully designed + it does provide non-blocking capability • However not easy to use correctly, a number of pitfalls • Many “innocent” looking parts of Servlet API may lead to blocking • e.g. request.getParameters() • For a good overview and perspective see Greg Wilkins’ talk • ”Into the Wild with Servlet 3.1 Async I/O” 13
  • 14. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Streams Spec for the JVM • Specification for non-blocking library interop • governs exchange of data across async boundaries • Collaborative effort • Kaazing, Netflix, Pivotal, RedHat, Twiiter, Typesafe • Momentum and growing ecosystem of libraries • network, database, etc. • On path to adoption in JDK 9 java.util.concurrent 14
  • 15. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15 onSubscribe onNext* (onError|onComplete)? Publisher Subscriber Subscription Reactive Streams API request(n) cancel()
  • 16. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Back-Pressure • A key part of Reactive Streams is back-pressure • It’s a type of flow control • Subscribers make requests for additional data • Publishers abide and produce what has been requested 16
  • 17. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Streams for Network I/O public interface ServerHttpRequest extends HttpRequest { Publisher<byte[]> getBody(); } public interface ServerHttpResponse extends HttpMessage { Publisher<Void> writeWith(Publisher<byte[]> publisher); } 17
  • 18. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Instead of... public interface ServerHttpRequest extends HttpRequest { InputStream getBody(); } public interface ServerHttpResponse extends HttpMessage { OutputStream getBody(); } 18
  • 19. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Streams over Servlet Runtime ? • Servlet 3.1 provides the non-blocking capability • Reactive Streams provides a non-blocking API with broad industry support • A single Reactive Streams pipeline • back-pressure through the layers (from DB to Web server) • Jetty is actively investigating this very option 19
  • 20. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Streams and Servlet 4.0 ??? • It is under discussion in the expert group • It would be great if it did happen • Potential obstacle is the Java EE 8 - JDK 8 association • Hopefully not a show-stopper since Reactive Streams is here today 20
  • 21. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Netty was designed from the ground up to be non-blocking • Easy to translate to Reactive Streams semantics • Two ongoing experiments • RxNetty • Reactor Net Reactive Streams Over Netty 21
  • 22. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Streams Network I/O Akka HTTP, Vert.x, Ratpack, Reactor Net, RxNetty* 22 *(via RxJava-ReactiveStreams bridge)
  • 23. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 23 Netty, Servlet 3.1 Reactive Streams Reactive Web App Stack
  • 24. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24 Web Framework Netty, Servlet 3.1 Reactive Streams Reactive Web App Stack
  • 25. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25 Web Framework Application Netty, Servlet 3.1 Reactive Streams Reactive Web App Stack
  • 26. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 26 Web Framework Application Netty, Servlet 3.1 Reactive Streams Reactive Streams HTTP Data Broker Reactive Web App Stack
  • 27. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ? 27 Web Framework Application Netty, Servlet 3.1 Reactive Streams Reactive Streams HTTP Data Broker ? API to compose asynchronous streams?
  • 28. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Working with Streams • Non-blocking services return Publisher<T> instead of <T> • How do you attach further processing? • Reactive Streams is a callback-based API • becomes very nested quickly • Need something more declarative • it’s beyond the scope of Reactive Streams 28
  • 29. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Publisher represents a stream of data • It’s natural to apply operations functional-style • like the Java 8 Stream • Need API for composing async logic • rise above callbacks Stream Operations 29
  • 30. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor Stream • Project Reactor provides a Stream API • Reactive Streams Publisher + composable operations 30 Streams.just('a' 'b' 'c') .take(2) .map(Character::toUpperCase) .consume(System.out::println);
  • 31. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Extensions (Rx) • Stream composition API based on Observer pattern • originated at Microsoft, work by Erik Meijer • Implemented for different languages -- RxJava, RxJS, Rx.NET, … 31 Observable.just('a', 'b', 'c') .take(2) .map(Character::toUpperCase) .subscribe(System.out::println);
  • 32. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RxJava and Reactive Streams • RxJava 1.x predates Reactive Streams and doesn’t implement it directly • Very similar concepts, different names • Observable-Observer vs Publisher-Subscriber • RxJava supports “reactive pull” back-pressure • RxJava 1.x - Reactive Streams bridge 32
  • 33. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo: HeadFirst 33
  • 34. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RxNetty • RxJava as the reactive bridge to Netty IO operations • Immediate and embedded client/server for TCP and HTTP • Decorating IO Read with rx.Observable and applying dynamic pull/push • Decorating IO Write with rx.Subscriber and requesting more on flush 34
  • 35. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RxNetty … what’s up • RxNetty has introduced Backpressure support in 0.5 • Powered by the backpressure protocol from RxJava • Overall the API has been heavily lifted too https://github.com/ReactiveX/RxNetty/wiki/0.5.x-FAQs 35
  • 36. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor Net 36 • Reactive Streams as the reactive bridge to Netty and ZeroMQ IO operations • Immediate and embedded client/server for TCP, UDP and HTTP • Decorating IO Read with Publisher and applying dynamic pull/push • Decorating IO Write with Subscriber and requesting more on flush
  • 37. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Member of the Reactor initiative • Reactor is a maturing Reactive Streams suite of libraries • As with a lot of the reactive libraries, observing a rapidly evolving set of API • Precluded Reactive Streams specification work • Now evolving and getting ready for Spring 5 Reactive story projectreactor.io , github.com/reactor 37
  • 38. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo: Back-Pressure 38
  • 39. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Async I/O with Reactive Streams • Never block on Applications Queues : Max(request) == Queue.capacity() • Keep Reading : Any asynchronous handoff is non-blocking • Make Writes Quicker : IO operation signals demand on availability • Optimize hardware resources : Claim bounded memory and cpu 39
  • 40. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Read One read implementation : Publisher stop-read • Consume NIO Buffers only when requested • request size is != bytes read • Application stopping reads propagates back-pressure • server buffers fill • client buffers fill • eventually throttles client 40
  • 41. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Write One write implementation : Subscriber request after flush • Request after flush indicates availability in write buffer • Request size is != bytes written • Write buffers filling naturally propagates back-pressure • buffers fill • no requests • eventually throttles application 41
  • 42. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Serialization Concerns • Subscription.request(n)is not absolute ( != bytes number ) • Decoding operations might produce one to many objects • must match subscriber capacity • Encoding operations might consume one to many byte chunks • must match buffering capacity • Available serialization libraries not built for chunked streams • Jackson, Kryo, Protobuf, etc. 42
  • 43. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo: Scatter-gather 43
  • 44. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Reactive 44
  • 45. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Reactive • Experimental work for Spring Framework 5 • Non-blocking runtimes -- Netty, Jetty, Tomcat • Reactive Streams over network I/O -- RxNetty, Reactor Net • Spring web processing 45
  • 46. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @RequestMapping("/capitalize") @ResponseBody public Publisher<Person> capitalize(@RequestBody Publisher<Person> persons) { // … } 46 Reactive Streams Publisher
  • 47. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @RequestMapping("/capitalize") @ResponseBody public Stream<Person> capitalize(@RequestBody Stream<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); } 47 Reactor Stream
  • 48. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @RequestMapping("/capitalize") @ResponseBody public Observable<Person> capitalize(@RequestBody Observable<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); } 48 RxJava Observable
  • 49. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ReactiveX On the Client Side 49
  • 50. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RxJS function() { StreamService.connect("stream") .flatMap(unpackCsv) .subscribe(updateUI, logError, logComplete); } var unpackCsv = function (ev) { return Rx.Observable.from(ev.data ? ev.data.split("n") : []) .filter(discardEmpty) .map(csvToJson) } 50
  • 51. Unless otherwise indicated these slides are © 2013-2014 Pivotal Software Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo: RxJS and Ratpack 51
  • 52. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 52 Learn More. Stay Connected. @springcentral Spring.io/video Thank You for Listening! @smaldini / @rstoya05