SlideShare a Scribd company logo
1 of 56
Download to read offline
ReactiveJava =
Reactive Programming
using RxJava
Hello!
I AM Hiten Pratap Singh
I am here because I love to dig in to experience new things.
You can find me at:
◦ hiten@nexthoughts.com
◦ http://github.com/hitenpratap/
◦ http://hprog99.wordpress.com/
I have divided this presentation into two parts
Reactive
Programming
RxJava
Reactive Programming
What’s Reactive Programming? What’s the big deal about it?
“
In computing, reactive programming is a
programming paradigm oriented around data
flows and the propagation of change.
Reactive Programming
Reactive programming is programming
with asynchronous data streams.
◦ Event buses or your typical click events are really
an asynchronous event stream
◦ Streams are cheap and ubiquitous, anything can be
a stream: variables, user inputs, properties etc.
◦ For example, imagine your Twitter feed would be
a data stream in the same fashion that click events
are.
Reactive Programming
On top of that, you are given an amazing
toolbox of functions to combine, create and
filter any of those streams.
◦ A stream can be used as an input to another one.
◦ You can merge two streams.
◦ You can filter a stream to get another one that has
only those events you are interested in.
◦ You can map data values from one stream to
another new one.
A stream is a sequence of ongoing events ordered in time. It can emit three
different things: a value (of some type), an error, or a "completed" signal.
Consider that the "completed" takes place, for instance, when the current window
or view containing that button is closed.
We capture these emitted events only asynchronously, by defining a function that
will execute when a value is emitted, another function when an error is emitted,
and another function when 'completed' is emitted.
The "listening" to the stream is called subscribing. The functions we are defining
are observers. The stream is the subject (or "observable") being observed. This is
precisely the Observer Design Pattern.
Reactive Programming
Why should I consider adopting RP?
◦ RP raises the level of abstraction of your code.
◦ Code in RP will likely be more concise.
◦ Apps nowadays have an abundancy of real-time
events of every kind that enable a highly
interactive experience to the user.
◦ We need tools for properly dealing with that, and
Reactive Programming is an answer.
Reactive Programming
Key Takeaways
◦ RP is a specification for dealing with
asynchronous streams of data.
◦ Reactive provides tools for transforming and
combining streams and for managing flow-control
◦ Resembles Java Streams API but the resemblance
is purely superficial
Thinking in RP with
Example
What’s ReactiveX?
◦ A library for composing async and event based
program by using observable sequences.
◦ Created by Microsoft initially for .Net platform by
Erik Meijer
◦ Extends observer pattern-
* Supports sequence of data and/or events
* Add operators that allow you to compose sequences
together declaratively
▫ Abstracts away concerns around
* Threading and Thread Safety
* Concurrent data structures and non blocking I/O
▫ RxJava is a port of Reactive Extensions created by
Netflix.
What’s ReactiveX?
RxJava
A libraryto use mightypowers of Reactive Programmingin Java!
Maven
Getting Started
Gradle
You can also include its jar file without having to use
any of build system as well.
Reactive Components/Building Blocks
ObserverObservable Subject
Observable
Observable
In ReactiveX an observer subscribes to an Observable. Then that
observer reacts to whatever item or sequence of items the
Observable emits.This patternfacilitatesconcurrent operations
because it does not need to block while waiting for the
Observable to emit objects,but insteadit creates a sentryin the
form of an observer that stands ready to react appropriatelyat
whatever future time the Observable does so.
◦ Emits zero or more values
◦ Life Cycles
* Notifies Observer using onNext(T)
* Completes with either onError() or onCompleted()
Operators
Operators By Categories
Creating
Observables
Transforming
Observables
Filtering
Observables
Combining
Observables
Error
handling
Operators
Observable
Utility
Operators
Operators By Categories(Contd.)
Conditional
and Boolean
Operators
Mathematical
and
Aggregate
Operators
Backpressure
Operators
ReactiveX provides great flexibility over operators by
letting us chaining them together or even creating new
ones.
Transforming Observable
Transforming Observable << Map
Transforming Observable << Flatmap
Filtering Observable
Filtering Observable << Take
Filtering Observable << Filter
Filtering Observable << Distinct
Filtering Observable << First
Combining Observable
Combining Observable << Merge
Combining Observable << Zip
Schedulers
If you want to introduce multithreadingintoyour cascade of
Observable operators, you can do so by instructingthose operators
(or particular Observables) to operate on particular Schedulers.
Observable Utility Operators
Observable Utility Operators << SubscribeOn
Observable Utility Operators << ObserveOn
Single
Single
◦ RxJava (and its derivatives like RxGroovy & RxScala) has developed
an Observable variant called “Single.”
◦ A Single is something like an Observable, but instead of emitting a
series of values — anywhere from none at all to an infinite number
— it always either emits one value or an error notification.
◦ For this reason, instead of subscribing to a Single with the three
methods you use to respond to notifications from an Observable
(onNext, onError, and onCompleted), you only use two methods to
subscribe:
Subjects
Subject
A Subject is a sort of bridge or proxy that is available in some
implementations of ReactiveX that acts both as an observer and as an
Observable. Because it is an observer, it can subscribe to one or more
Observables, and because it is an Observable, it can pass through the
items it observes by reemitting them, and it can also emit new items.
Because a Subject subscribes to an Observable, it will trigger that
Observable to begin emitting items (if that Observable is “cold” — that
is, if it waits for a subscription before it begins to emit items). This can
have the effect of making the resulting Subject a “hot” Observable
variant of the original “cold” Observable.
Varieties of Subject
◦ AsyncSubject
◦ BehaviorSubject
◦ PublishSubject
◦ ReplaySubject
Subject << AsyncSubject
Subject << BehaviorSubject
Subject << PublishSubject
Subject << ReplaySubject
Backpressure
Backpressure
In RxJava it is not difficult to get into a situation in which an Observable
is emitting items more rapidly than an operator or subscriber can
consume them. This presents the problem of what to do with such a
growing backlog of unconsumed items.
For example, imagine using the zip operator to zip together two infinite
Observables, one of which emits items twice as frequently as the other.
A naive implementation of the zip operator would have to maintain an
ever-expanding buffer of items emitted by the faster Observable to
eventually combine with items emitted by the slower one. This could
cause RxJava to seize an unwieldy amount of system resources.
Hot and Cold
Observable
Hot Observable
A hot Observable begins generating items to emit immediately when it
is created. Subscribers typically begin observing the sequence of items
emitted by a hot Observable from somewhere in the middle of the
sequence, beginning with the first item emitted by the Observable
subsequent to the establishment of the subscription.
Such an Observable emits items at its own pace, and it is up to its
observers to keep up.
Examples of items emitted by a hot Observable might include mouse &
keyboard events, system events, or stock prices.
Cold Observable
A cold Observable emits a particular sequence of items, but can begin
emitting this sequence when its Observer finds it to be convenient, and
at whatever rate the Observer desires, without disrupting the integrity of
the sequence.
For example if you convert a static Iterable into an Observable, that
Observable will emit the same sequence of items no matter when it is
later subscribed to or how frequently those items are observed.
Examples of items emitted by a cold Observable might include the
results of a database query, file retrieval, or web request.
Conclusion
Pros
◦ Makes Async code easy to develop
◦ Lots of resources to get started with
◦ Strong use of functional type programming
◦ Netflix used RxNetty and Reactive Programmingto
considerable performance advantage over Tomcat
◦ Web Service clients like Jerseyand Retrofit support RxJava.
Cons
◦ Learning curve and mind set change to use functional reactive
programming
◦ Appears like more code and more complex code initially–
Requires time for it to grow on you.
◦ If on Java 7 anonymous class would make this a non-starter.
Thanks!
ANY QUESTIONS?
You can find me at:
hiten@nexthoughts.com
http://github.com/hitenpratap/
http://hprog99.wordpress.com/

More Related Content

What's hot

Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster OpenCredo
 
Demystifying Reactive Programming
Demystifying Reactive ProgrammingDemystifying Reactive Programming
Demystifying Reactive ProgrammingTom Bulatewicz, PhD
 
Reactive: Programming -> Systems -> Architecture
Reactive: Programming -> Systems -> ArchitectureReactive: Programming -> Systems -> Architecture
Reactive: Programming -> Systems -> ArchitectureAleksey Izmailov
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingSUDIP GHOSH
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
Reactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorReactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorKnoldus Inc.
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingFlorian Stefan
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5Gal Marder
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingHung Hoang
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminarGal Marder
 
Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!Massimo Bonanni
 
Coordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud ContractCoordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud ContractOmri Spector
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to AkkaKnoldus Inc.
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8Johan Andrén
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelMassimo Bonanni
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malikLama K Banna
 
Gatling - Stress test tool
Gatling - Stress test toolGatling - Stress test tool
Gatling - Stress test toolKnoldus Inc.
 
Introduction to Functional Reactive Programming
Introduction to Functional Reactive ProgrammingIntroduction to Functional Reactive Programming
Introduction to Functional Reactive ProgrammingĐặng Thái Sơn
 

What's hot (20)

Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster
 
Demystifying Reactive Programming
Demystifying Reactive ProgrammingDemystifying Reactive Programming
Demystifying Reactive Programming
 
Grails with swagger
Grails with swaggerGrails with swagger
Grails with swagger
 
Reactive: Programming -> Systems -> Architecture
Reactive: Programming -> Systems -> ArchitectureReactive: Programming -> Systems -> Architecture
Reactive: Programming -> Systems -> Architecture
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Reactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorReactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project Reactor
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive Programming
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
 
Load test REST APIs using gatling
Load test REST APIs using gatlingLoad test REST APIs using gatling
Load test REST APIs using gatling
 
Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!Durable Functions vs Logic App : la guerra dei workflow!!
Durable Functions vs Logic App : la guerra dei workflow!!
 
Coordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud ContractCoordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud Contract
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to Akka
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
 
Gatling - Stress test tool
Gatling - Stress test toolGatling - Stress test tool
Gatling - Stress test tool
 
Introduction to Functional Reactive Programming
Introduction to Functional Reactive ProgrammingIntroduction to Functional Reactive Programming
Introduction to Functional Reactive Programming
 

Viewers also liked (16)

Jsoup
JsoupJsoup
Jsoup
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Introduction to es6
Introduction to es6Introduction to es6
Introduction to es6
 
Hamcrest
HamcrestHamcrest
Hamcrest
 
Apache tika
Apache tikaApache tika
Apache tika
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
 
Progressive Web-App (PWA)
Progressive Web-App (PWA)Progressive Web-App (PWA)
Progressive Web-App (PWA)
 
Jmh
JmhJmh
Jmh
 
JFree chart
JFree chartJFree chart
JFree chart
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Spring Web Flow
Spring Web FlowSpring Web Flow
Spring Web Flow
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Cosmos DB Service
Cosmos DB ServiceCosmos DB Service
Cosmos DB Service
 
Actors model in gpars
Actors model in gparsActors model in gpars
Actors model in gpars
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Vertx
VertxVertx
Vertx
 

Similar to Reactive java - Reactive Programming + RxJava

Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft
 
Streamlining with rx
Streamlining with rxStreamlining with rx
Streamlining with rxAkhil Dad
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVMNetesh Kumar
 
RxJava pour Android : présentation lors du GDG Android Montréal
RxJava pour Android : présentation lors du GDG Android MontréalRxJava pour Android : présentation lors du GDG Android Montréal
RxJava pour Android : présentation lors du GDG Android MontréalSidereo
 
Strange Async Code - ReaxtiveX
Strange Async Code - ReaxtiveXStrange Async Code - ReaxtiveX
Strange Async Code - ReaxtiveXMatthew Will
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingAraf Karsh Hamid
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in AngularKnoldus Inc.
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingAraf Karsh Hamid
 
Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programmingDwi Randy Herdinanto
 
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrxIlia Idakiev
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 SlidesYarikS
 

Similar to Reactive java - Reactive Programming + RxJava (20)

Intro to Rx Java
Intro to Rx JavaIntro to Rx Java
Intro to Rx Java
 
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on AndroidSperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft Talks: RxJava Functional Reactive Programming on Android
 
RxJava@Android
RxJava@AndroidRxJava@Android
RxJava@Android
 
Streamlining with rx
Streamlining with rxStreamlining with rx
Streamlining with rx
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVM
 
RxJava pour Android : présentation lors du GDG Android Montréal
RxJava pour Android : présentation lors du GDG Android MontréalRxJava pour Android : présentation lors du GDG Android Montréal
RxJava pour Android : présentation lors du GDG Android Montréal
 
Strange Async Code - ReaxtiveX
Strange Async Code - ReaxtiveXStrange Async Code - ReaxtiveX
Strange Async Code - ReaxtiveX
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Rx Swift
Rx SwiftRx Swift
Rx Swift
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in Angular
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programming
 
DZone_RC_RxJS
DZone_RC_RxJSDZone_RC_RxJS
DZone_RC_RxJS
 
RxSwift
RxSwiftRxSwift
RxSwift
 
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrx
 
Rx java workshop
Rx java workshop Rx java workshop
Rx java workshop
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Reactive Applications in Java
Reactive Applications in JavaReactive Applications in Java
Reactive Applications in Java
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
 

More from NexThoughts Technologies (20)

Alexa skill
Alexa skillAlexa skill
Alexa skill
 
GraalVM
GraalVMGraalVM
GraalVM
 
Docker & kubernetes
Docker & kubernetesDocker & kubernetes
Docker & kubernetes
 
Apache commons
Apache commonsApache commons
Apache commons
 
HazelCast
HazelCastHazelCast
HazelCast
 
MySQL Pro
MySQL ProMySQL Pro
MySQL Pro
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & Redux
 
Swagger
SwaggerSwagger
Swagger
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Arango DB
Arango DBArango DB
Arango DB
 
Jython
JythonJython
Jython
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Smart Contract samples
Smart Contract samplesSmart Contract samples
Smart Contract samples
 
My Doc of geth
My Doc of gethMy Doc of geth
My Doc of geth
 
Geth important commands
Geth important commandsGeth important commands
Geth important commands
 
Ethereum genesis
Ethereum genesisEthereum genesis
Ethereum genesis
 
Ethereum
EthereumEthereum
Ethereum
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Google authentication
Google authenticationGoogle authentication
Google authentication
 

Recently uploaded

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

Reactive java - Reactive Programming + RxJava

  • 2. Hello! I AM Hiten Pratap Singh I am here because I love to dig in to experience new things. You can find me at: ◦ hiten@nexthoughts.com ◦ http://github.com/hitenpratap/ ◦ http://hprog99.wordpress.com/
  • 3. I have divided this presentation into two parts Reactive Programming RxJava
  • 4. Reactive Programming What’s Reactive Programming? What’s the big deal about it?
  • 5.
  • 6. “ In computing, reactive programming is a programming paradigm oriented around data flows and the propagation of change.
  • 7. Reactive Programming Reactive programming is programming with asynchronous data streams. ◦ Event buses or your typical click events are really an asynchronous event stream ◦ Streams are cheap and ubiquitous, anything can be a stream: variables, user inputs, properties etc. ◦ For example, imagine your Twitter feed would be a data stream in the same fashion that click events are.
  • 8. Reactive Programming On top of that, you are given an amazing toolbox of functions to combine, create and filter any of those streams. ◦ A stream can be used as an input to another one. ◦ You can merge two streams. ◦ You can filter a stream to get another one that has only those events you are interested in. ◦ You can map data values from one stream to another new one.
  • 9. A stream is a sequence of ongoing events ordered in time. It can emit three different things: a value (of some type), an error, or a "completed" signal. Consider that the "completed" takes place, for instance, when the current window or view containing that button is closed. We capture these emitted events only asynchronously, by defining a function that will execute when a value is emitted, another function when an error is emitted, and another function when 'completed' is emitted. The "listening" to the stream is called subscribing. The functions we are defining are observers. The stream is the subject (or "observable") being observed. This is precisely the Observer Design Pattern.
  • 10. Reactive Programming Why should I consider adopting RP? ◦ RP raises the level of abstraction of your code. ◦ Code in RP will likely be more concise. ◦ Apps nowadays have an abundancy of real-time events of every kind that enable a highly interactive experience to the user. ◦ We need tools for properly dealing with that, and Reactive Programming is an answer.
  • 11. Reactive Programming Key Takeaways ◦ RP is a specification for dealing with asynchronous streams of data. ◦ Reactive provides tools for transforming and combining streams and for managing flow-control ◦ Resembles Java Streams API but the resemblance is purely superficial
  • 12. Thinking in RP with Example
  • 14. ◦ A library for composing async and event based program by using observable sequences. ◦ Created by Microsoft initially for .Net platform by Erik Meijer ◦ Extends observer pattern- * Supports sequence of data and/or events * Add operators that allow you to compose sequences together declaratively ▫ Abstracts away concerns around * Threading and Thread Safety * Concurrent data structures and non blocking I/O ▫ RxJava is a port of Reactive Extensions created by Netflix. What’s ReactiveX?
  • 15. RxJava A libraryto use mightypowers of Reactive Programmingin Java!
  • 16. Maven Getting Started Gradle You can also include its jar file without having to use any of build system as well.
  • 19. Observable In ReactiveX an observer subscribes to an Observable. Then that observer reacts to whatever item or sequence of items the Observable emits.This patternfacilitatesconcurrent operations because it does not need to block while waiting for the Observable to emit objects,but insteadit creates a sentryin the form of an observer that stands ready to react appropriatelyat whatever future time the Observable does so. ◦ Emits zero or more values ◦ Life Cycles * Notifies Observer using onNext(T) * Completes with either onError() or onCompleted()
  • 20.
  • 23. Operators By Categories(Contd.) Conditional and Boolean Operators Mathematical and Aggregate Operators Backpressure Operators ReactiveX provides great flexibility over operators by letting us chaining them together or even creating new ones.
  • 35. Schedulers If you want to introduce multithreadingintoyour cascade of Observable operators, you can do so by instructingthose operators (or particular Observables) to operate on particular Schedulers.
  • 40. Single ◦ RxJava (and its derivatives like RxGroovy & RxScala) has developed an Observable variant called “Single.” ◦ A Single is something like an Observable, but instead of emitting a series of values — anywhere from none at all to an infinite number — it always either emits one value or an error notification. ◦ For this reason, instead of subscribing to a Single with the three methods you use to respond to notifications from an Observable (onNext, onError, and onCompleted), you only use two methods to subscribe:
  • 42. Subject A Subject is a sort of bridge or proxy that is available in some implementations of ReactiveX that acts both as an observer and as an Observable. Because it is an observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items. Because a Subject subscribes to an Observable, it will trigger that Observable to begin emitting items (if that Observable is “cold” — that is, if it waits for a subscription before it begins to emit items). This can have the effect of making the resulting Subject a “hot” Observable variant of the original “cold” Observable.
  • 43. Varieties of Subject ◦ AsyncSubject ◦ BehaviorSubject ◦ PublishSubject ◦ ReplaySubject
  • 49. Backpressure In RxJava it is not difficult to get into a situation in which an Observable is emitting items more rapidly than an operator or subscriber can consume them. This presents the problem of what to do with such a growing backlog of unconsumed items. For example, imagine using the zip operator to zip together two infinite Observables, one of which emits items twice as frequently as the other. A naive implementation of the zip operator would have to maintain an ever-expanding buffer of items emitted by the faster Observable to eventually combine with items emitted by the slower one. This could cause RxJava to seize an unwieldy amount of system resources.
  • 51. Hot Observable A hot Observable begins generating items to emit immediately when it is created. Subscribers typically begin observing the sequence of items emitted by a hot Observable from somewhere in the middle of the sequence, beginning with the first item emitted by the Observable subsequent to the establishment of the subscription. Such an Observable emits items at its own pace, and it is up to its observers to keep up. Examples of items emitted by a hot Observable might include mouse & keyboard events, system events, or stock prices.
  • 52. Cold Observable A cold Observable emits a particular sequence of items, but can begin emitting this sequence when its Observer finds it to be convenient, and at whatever rate the Observer desires, without disrupting the integrity of the sequence. For example if you convert a static Iterable into an Observable, that Observable will emit the same sequence of items no matter when it is later subscribed to or how frequently those items are observed. Examples of items emitted by a cold Observable might include the results of a database query, file retrieval, or web request.
  • 54. Pros ◦ Makes Async code easy to develop ◦ Lots of resources to get started with ◦ Strong use of functional type programming ◦ Netflix used RxNetty and Reactive Programmingto considerable performance advantage over Tomcat ◦ Web Service clients like Jerseyand Retrofit support RxJava.
  • 55. Cons ◦ Learning curve and mind set change to use functional reactive programming ◦ Appears like more code and more complex code initially– Requires time for it to grow on you. ◦ If on Java 7 anonymous class would make this a non-starter.
  • 56. Thanks! ANY QUESTIONS? You can find me at: hiten@nexthoughts.com http://github.com/hitenpratap/ http://hprog99.wordpress.com/