SlideShare uma empresa Scribd logo
1 de 36
Reactive Programming in Java 8
with Rx-Java
Kasun Indrasiri
Software Architect, WSO2
January 2016
Why Reactive Programming?
• Why another programming paradigm?
• Things are different now!
• Conventional software applications won’t be able to fulfill the
modern enterprise needs.
• Its time to rethink about our software architecture patterns and
programming techniques.
What it actually means to be Reactive?
• “Readily responsive to a stimulus” - merriam-webster
• Reactive Systems :
• responds in a timely manner
• stays responsive in the face of failure
• stays responsive under varying workload
• rely on asynchronous message-passing
Reactive Programming
• A programming paradigm that helps you to build
‘Reactive Systems’. E.g.: Google Spreadsheet
• In a reactive world, we can't just wait for a function
result, a network call, or a database query to return.
• Every moment we wait for something, we lose the
opportunity to do other things in parallel.
• Reactive programming can be done in several ways
• Akka Actors
• Reactive Extensions (Rx) – reactive + functional
Why Rx-Java?
• The Netflix story..
The Netflix API
• How to reducing network chattiness?
• Granular API.
• client applications to make multiple calls that need to be assembled in order
to render a single user experience
The Netflix API
• Discrete requests from devices, should be collapsed into
a single request
• Server-side concurrency is needed to effectively reduce
network chattiness.
• Nested, conditional, parallel execution of backend
network calls.
Embrace Concurrency
• Blocking calls?... Not anymore.
• Server-side concurrency is a must.
• Low level primitive of concurrency.
• Concurrent programming is hard!
Java Futures
• Represents the result of an asynchronous computation.
• Can be used to retrieve the result asynchronously at a
later point in time
• Cons:
• Retrieving value from future is a blocking call : Future.get()
• Messy with Nested Futures -> complex to implement/maintain.
Callbacks
• A callback is a piece of executable code that is passed as
an argument to other code, which is expected to call
back the argument at some convenient time.
Callbacks
• Use case :
• Client send a request to the Application
• Application calls service A
• Get the response from ServiceA and send it to service B
• Get the response from ServiceB and send it to Service C
• Get the response from ServiceC and send it to the Client
Service A
Service B
Service C
1
2
3
ApplicationClient
Callbacks
• Callback Hell!
• Callbacks based applications get extremely complex when we have nested
callbacks.
• Leads to messy code, hard to troubleshoot.
• Example : https://github.com/kasun04/rnd/tree/master/rx-
java/src/main/java/org/kasun/rnd/rxjava/serviceinvoker/callback
Reactive Extensions - Rx
• ReactiveX is a library for composing asynchronous and
event-based programs by using observable sequences.
• ‘The Observer pattern done right.’
• Initially implemented for C# by Microsoft, later ported to
many languages by Netflix Rx.
• Rx-Java is the Java implementation.
Observer Pattern
• ‘Subject’ notifies the ‘observers’ when a change has
happened in the subject.
Observable
• Rx-Java introduces ‘Observable’ data type by extending
the traditional Observer Pattern.
Observers
Observable
Observable vs Observer Pattern
• The producer signal that there is no more data available:
the
• onCompleted() event
• The producer can signal that an error occurred
• onError() event
Observable and Subscriber
• The producer signal that there is no more data available:
the
ObservableSubscriber
subscribe
onNext*
onCompleted
Observable and Subscriber – In Action
Creating Observable
• Observable.create()
• Observable.just()
• Observable.from()
Observable and Operators
• Observable -> Operator -> Subscriber
Filtering Observables
• Selectively emit items from a source Observable
Filtering Observables
• Filtering Operators
Transforming Observables
• Transform items that are emitted by an Observable
Transforming Observables
• Transforming Operators
Filtering and Transforming – In Action
Transforming Observables
• FlatMap
• Observable.flatMap() takes the emissions of one Observable and returns the
emissions of another Observable to take its place.
Observable<List<String>> query(String text){...}
query("Hello, world!")
.flatMap(new Func1<List<String>, Observable<String>>() {
@Override
public Observable<String> call(List<String> urls) {
return Observable.from(urls);
}
})
.subscribe(url -> System.out.println(url));
FlatMap – In Action
More Operators
• Combining Observables
• Error Handling Operators
• Observable Utility Operators
• Conditional and Boolean Operators
http://reactivex.io/documentation/operators.html
Rx-Java in Action
• Use case : Service Orchestration
Source Code : https://github.com/kasun04/rnd/tree/master/rx-
java/src/main/java/org/kasun/rnd/rxjava/serviceinvoker/rx/nonblocking
Service A
Service B
Service C
1
2
3
ApplicationClient
Scheduler
• Rx is single threaded by default.
• Schedulers are the easiest way to bring multi-threading
into your apps.
• subscribeOn
• observerOn
Scheduler
• Schedulers.io(): meant for I/O-bound work
• Schedulers.computation(): meant for computational
work such as event-loops
• Schedulers.newThread(): creates a new thread for
each unit of work
Rx-Java in Action
• Use case : Service Orchestration with Schedulers
Source Code : https://github.com/kasun04/rnd/tree/master/rx-
java/src/main/java/org/kasun/rnd/rxjava/serviceinvoker/rx/nonblocking
Service A
Service B
Service C
1
2
3
ApplicationClient
Conclusion
• Get rid of blocking code!
• Think ‘non-blocking’
• Think reactive
• Rx-Java – steep learning curve
• Develop use cases
• Leverage Java 8
Questions?
References
• http://reactivex.io/documentation
• http://blog.danlew.net/2014/09/15/grokking-rxjava-
part-1/
• http://techblog.netflix.com/2013/02/rxjava-netflix-
api.html
• Source Code :
https://github.com/kasun04/rnd/tree/master/rx-java
Thank You

Mais conteúdo relacionado

Mais procurados

Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Michel Schudel
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingSUDIP GHOSH
 
Introduction to Spring webflux
Introduction to Spring webfluxIntroduction to Spring webflux
Introduction to Spring webfluxKnoldus Inc.
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJavaJobaer Chowdhury
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllThomas Wuerthinger
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
The Eclipse Transformer Project
The Eclipse Transformer Project The Eclipse Transformer Project
The Eclipse Transformer Project Jakarta_EE
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Bootvipin kumar
 
Kafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around KafkaKafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around KafkaGuido Schmutz
 
How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?Albert Chen
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerKoichi Sakata
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Scrum Breakfast Vietnam
 

Mais procurados (20)

Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Introduction to Spring webflux
Introduction to Spring webfluxIntroduction to Spring webflux
Introduction to Spring webflux
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
Spring Webflux
Spring WebfluxSpring Webflux
Spring Webflux
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
The Eclipse Transformer Project
The Eclipse Transformer Project The Eclipse Transformer Project
The Eclipse Transformer Project
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Boot
 
Kafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around KafkaKafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around Kafka
 
Graphql
GraphqlGraphql
Graphql
 
How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
 

Semelhante a Reactive Programming in Java 8 with Rx-Java

Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in JavaYakov Fain
 
Fault Tolerance in Distributed Environment
Fault Tolerance in Distributed EnvironmentFault Tolerance in Distributed Environment
Fault Tolerance in Distributed EnvironmentOrkhan Gasimov
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqRuben Tan
 
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Flink Forward
 
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorOrenEzer1
 
Designing Fault Tolerant Microservices
Designing Fault Tolerant MicroservicesDesigning Fault Tolerant Microservices
Designing Fault Tolerant MicroservicesOrkhan Gasimov
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?hawkowl
 
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...Vyacheslav Lapin
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debuggerIulian Dragos
 
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSupun Dissanayake
 
Микросервисы со Spring Boot & Spring Cloud
Микросервисы со Spring Boot & Spring CloudМикросервисы со Spring Boot & Spring Cloud
Микросервисы со Spring Boot & Spring CloudVitebsk DSC
 
The Need of Cloud-Native Application
The Need of Cloud-Native ApplicationThe Need of Cloud-Native Application
The Need of Cloud-Native ApplicationEmiliano Pecis
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)Rajat Pratap Singh
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Yakov Fain
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Pavel Chunyayev
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLMorgan Dedmon
 
Meteor Boulder meetup #1
Meteor Boulder meetup #1Meteor Boulder meetup #1
Meteor Boulder meetup #1Robert Dickert
 
Building a document e-signing workflow with Azure Durable Functions
Building a document e-signing workflow with Azure Durable FunctionsBuilding a document e-signing workflow with Azure Durable Functions
Building a document e-signing workflow with Azure Durable FunctionsJoonas Westlin
 

Semelhante a Reactive Programming in Java 8 with Rx-Java (20)

Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Fault Tolerance in Distributed Environment
Fault Tolerance in Distributed EnvironmentFault Tolerance in Distributed Environment
Fault Tolerance in Distributed Environment
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
 
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactor
 
Designing Fault Tolerant Microservices
Designing Fault Tolerant MicroservicesDesigning Fault Tolerant Microservices
Designing Fault Tolerant Microservices
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
 
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
 
Микросервисы со Spring Boot & Spring Cloud
Микросервисы со Spring Boot & Spring CloudМикросервисы со Spring Boot & Spring Cloud
Микросервисы со Spring Boot & Spring Cloud
 
The Need of Cloud-Native Application
The Need of Cloud-Native ApplicationThe Need of Cloud-Native Application
The Need of Cloud-Native Application
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)
 
Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
 
Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015Ansible benelux meetup - Amsterdam 27-5-2015
Ansible benelux meetup - Amsterdam 27-5-2015
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
 
Meteor Boulder meetup #1
Meteor Boulder meetup #1Meteor Boulder meetup #1
Meteor Boulder meetup #1
 
Building a document e-signing workflow with Azure Durable Functions
Building a document e-signing workflow with Azure Durable FunctionsBuilding a document e-signing workflow with Azure Durable Functions
Building a document e-signing workflow with Azure Durable Functions
 

Mais de Kasun Indrasiri

Microservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaMicroservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaKasun Indrasiri
 
Adaptive and Iterative Integration for Microservices and Cloud Native Archite...
Adaptive and Iterative Integration for Microservices and Cloud Native Archite...Adaptive and Iterative Integration for Microservices and Cloud Native Archite...
Adaptive and Iterative Integration for Microservices and Cloud Native Archite...Kasun Indrasiri
 
Microservices for Enterprises
Microservices for Enterprises Microservices for Enterprises
Microservices for Enterprises Kasun Indrasiri
 
Bridging Microservices, APIs and Integration
Bridging Microservices, APIs and IntegrationBridging Microservices, APIs and Integration
Bridging Microservices, APIs and IntegrationKasun Indrasiri
 
Integration Microservices
Integration MicroservicesIntegration Microservices
Integration MicroservicesKasun Indrasiri
 
The Role of Enterprise Integration in Digital Transformation
The Role of Enterprise Integration in Digital TransformationThe Role of Enterprise Integration in Digital Transformation
The Role of Enterprise Integration in Digital TransformationKasun Indrasiri
 
Deep-dive into WSO2 ESB 5.0
Deep-dive into WSO2 ESB 5.0 Deep-dive into WSO2 ESB 5.0
Deep-dive into WSO2 ESB 5.0 Kasun Indrasiri
 
Microservices in Practice
Microservices in PracticeMicroservices in Practice
Microservices in PracticeKasun Indrasiri
 
WSO2-ESB - The backbone of Enterprise Integration
WSO2-ESB - The backbone of Enterprise IntegrationWSO2-ESB - The backbone of Enterprise Integration
WSO2-ESB - The backbone of Enterprise IntegrationKasun Indrasiri
 
Introduction to WSO2 Integration Platform
Introduction to WSO2 Integration PlatformIntroduction to WSO2 Integration Platform
Introduction to WSO2 Integration PlatformKasun Indrasiri
 
The Middleware technology that connects the enterprise
The Middleware technology that connects the enterpriseThe Middleware technology that connects the enterprise
The Middleware technology that connects the enterprise Kasun Indrasiri
 
API, Integration, and SOA Convergence
API, Integration, and SOA ConvergenceAPI, Integration, and SOA Convergence
API, Integration, and SOA ConvergenceKasun Indrasiri
 
The Past, Present and Future of Enterprise Integration
The Past, Present and Future of  Enterprise IntegrationThe Past, Present and Future of  Enterprise Integration
The Past, Present and Future of Enterprise IntegrationKasun Indrasiri
 
WSO2 ESB - The Backbone of Integration
WSO2 ESB - The Backbone of Integration WSO2 ESB - The Backbone of Integration
WSO2 ESB - The Backbone of Integration Kasun Indrasiri
 

Mais de Kasun Indrasiri (17)

Microservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaMicroservices Integration Patterns with Kafka
Microservices Integration Patterns with Kafka
 
Adaptive and Iterative Integration for Microservices and Cloud Native Archite...
Adaptive and Iterative Integration for Microservices and Cloud Native Archite...Adaptive and Iterative Integration for Microservices and Cloud Native Archite...
Adaptive and Iterative Integration for Microservices and Cloud Native Archite...
 
Microservices for Enterprises
Microservices for Enterprises Microservices for Enterprises
Microservices for Enterprises
 
Bridging Microservices, APIs and Integration
Bridging Microservices, APIs and IntegrationBridging Microservices, APIs and Integration
Bridging Microservices, APIs and Integration
 
Integration Microservices
Integration MicroservicesIntegration Microservices
Integration Microservices
 
The Role of Enterprise Integration in Digital Transformation
The Role of Enterprise Integration in Digital TransformationThe Role of Enterprise Integration in Digital Transformation
The Role of Enterprise Integration in Digital Transformation
 
Deep-dive into WSO2 ESB 5.0
Deep-dive into WSO2 ESB 5.0 Deep-dive into WSO2 ESB 5.0
Deep-dive into WSO2 ESB 5.0
 
Microintegration
MicrointegrationMicrointegration
Microintegration
 
Microservices in Practice
Microservices in PracticeMicroservices in Practice
Microservices in Practice
 
WSO2-ESB - The backbone of Enterprise Integration
WSO2-ESB - The backbone of Enterprise IntegrationWSO2-ESB - The backbone of Enterprise Integration
WSO2-ESB - The backbone of Enterprise Integration
 
Introduction to WSO2 Integration Platform
Introduction to WSO2 Integration PlatformIntroduction to WSO2 Integration Platform
Introduction to WSO2 Integration Platform
 
WSO2 Gateway
WSO2 GatewayWSO2 Gateway
WSO2 Gateway
 
The Middleware technology that connects the enterprise
The Middleware technology that connects the enterpriseThe Middleware technology that connects the enterprise
The Middleware technology that connects the enterprise
 
API, Integration, and SOA Convergence
API, Integration, and SOA ConvergenceAPI, Integration, and SOA Convergence
API, Integration, and SOA Convergence
 
The Past, Present and Future of Enterprise Integration
The Past, Present and Future of  Enterprise IntegrationThe Past, Present and Future of  Enterprise Integration
The Past, Present and Future of Enterprise Integration
 
WSO2 ESB - The Backbone of Integration
WSO2 ESB - The Backbone of Integration WSO2 ESB - The Backbone of Integration
WSO2 ESB - The Backbone of Integration
 
Connected Retail
Connected RetailConnected Retail
Connected Retail
 

Último

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 

Último (20)

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 

Reactive Programming in Java 8 with Rx-Java

  • 1. Reactive Programming in Java 8 with Rx-Java Kasun Indrasiri Software Architect, WSO2 January 2016
  • 2. Why Reactive Programming? • Why another programming paradigm? • Things are different now! • Conventional software applications won’t be able to fulfill the modern enterprise needs. • Its time to rethink about our software architecture patterns and programming techniques.
  • 3. What it actually means to be Reactive? • “Readily responsive to a stimulus” - merriam-webster • Reactive Systems : • responds in a timely manner • stays responsive in the face of failure • stays responsive under varying workload • rely on asynchronous message-passing
  • 4. Reactive Programming • A programming paradigm that helps you to build ‘Reactive Systems’. E.g.: Google Spreadsheet • In a reactive world, we can't just wait for a function result, a network call, or a database query to return. • Every moment we wait for something, we lose the opportunity to do other things in parallel. • Reactive programming can be done in several ways • Akka Actors • Reactive Extensions (Rx) – reactive + functional
  • 5. Why Rx-Java? • The Netflix story..
  • 6. The Netflix API • How to reducing network chattiness? • Granular API. • client applications to make multiple calls that need to be assembled in order to render a single user experience
  • 7. The Netflix API • Discrete requests from devices, should be collapsed into a single request • Server-side concurrency is needed to effectively reduce network chattiness. • Nested, conditional, parallel execution of backend network calls.
  • 8. Embrace Concurrency • Blocking calls?... Not anymore. • Server-side concurrency is a must. • Low level primitive of concurrency. • Concurrent programming is hard!
  • 9. Java Futures • Represents the result of an asynchronous computation. • Can be used to retrieve the result asynchronously at a later point in time • Cons: • Retrieving value from future is a blocking call : Future.get() • Messy with Nested Futures -> complex to implement/maintain.
  • 10. Callbacks • A callback is a piece of executable code that is passed as an argument to other code, which is expected to call back the argument at some convenient time.
  • 11. Callbacks • Use case : • Client send a request to the Application • Application calls service A • Get the response from ServiceA and send it to service B • Get the response from ServiceB and send it to Service C • Get the response from ServiceC and send it to the Client Service A Service B Service C 1 2 3 ApplicationClient
  • 12. Callbacks • Callback Hell! • Callbacks based applications get extremely complex when we have nested callbacks. • Leads to messy code, hard to troubleshoot. • Example : https://github.com/kasun04/rnd/tree/master/rx- java/src/main/java/org/kasun/rnd/rxjava/serviceinvoker/callback
  • 13. Reactive Extensions - Rx • ReactiveX is a library for composing asynchronous and event-based programs by using observable sequences. • ‘The Observer pattern done right.’ • Initially implemented for C# by Microsoft, later ported to many languages by Netflix Rx. • Rx-Java is the Java implementation.
  • 14. Observer Pattern • ‘Subject’ notifies the ‘observers’ when a change has happened in the subject.
  • 15. Observable • Rx-Java introduces ‘Observable’ data type by extending the traditional Observer Pattern. Observers Observable
  • 16. Observable vs Observer Pattern • The producer signal that there is no more data available: the • onCompleted() event • The producer can signal that an error occurred • onError() event
  • 17. Observable and Subscriber • The producer signal that there is no more data available: the ObservableSubscriber subscribe onNext* onCompleted
  • 18. Observable and Subscriber – In Action
  • 19. Creating Observable • Observable.create() • Observable.just() • Observable.from()
  • 20. Observable and Operators • Observable -> Operator -> Subscriber
  • 21. Filtering Observables • Selectively emit items from a source Observable
  • 23. Transforming Observables • Transform items that are emitted by an Observable
  • 25. Filtering and Transforming – In Action
  • 26. Transforming Observables • FlatMap • Observable.flatMap() takes the emissions of one Observable and returns the emissions of another Observable to take its place. Observable<List<String>> query(String text){...} query("Hello, world!") .flatMap(new Func1<List<String>, Observable<String>>() { @Override public Observable<String> call(List<String> urls) { return Observable.from(urls); } }) .subscribe(url -> System.out.println(url));
  • 27. FlatMap – In Action
  • 28. More Operators • Combining Observables • Error Handling Operators • Observable Utility Operators • Conditional and Boolean Operators http://reactivex.io/documentation/operators.html
  • 29. Rx-Java in Action • Use case : Service Orchestration Source Code : https://github.com/kasun04/rnd/tree/master/rx- java/src/main/java/org/kasun/rnd/rxjava/serviceinvoker/rx/nonblocking Service A Service B Service C 1 2 3 ApplicationClient
  • 30. Scheduler • Rx is single threaded by default. • Schedulers are the easiest way to bring multi-threading into your apps. • subscribeOn • observerOn
  • 31. Scheduler • Schedulers.io(): meant for I/O-bound work • Schedulers.computation(): meant for computational work such as event-loops • Schedulers.newThread(): creates a new thread for each unit of work
  • 32. Rx-Java in Action • Use case : Service Orchestration with Schedulers Source Code : https://github.com/kasun04/rnd/tree/master/rx- java/src/main/java/org/kasun/rnd/rxjava/serviceinvoker/rx/nonblocking Service A Service B Service C 1 2 3 ApplicationClient
  • 33. Conclusion • Get rid of blocking code! • Think ‘non-blocking’ • Think reactive • Rx-Java – steep learning curve • Develop use cases • Leverage Java 8
  • 35. References • http://reactivex.io/documentation • http://blog.danlew.net/2014/09/15/grokking-rxjava- part-1/ • http://techblog.netflix.com/2013/02/rxjava-netflix- api.html • Source Code : https://github.com/kasun04/rnd/tree/master/rx-java