SlideShare a Scribd company logo
Agenda
• What	is	Reac+ve?	
• Flux	basics	
• Marble	diagrams	
• Cold	Fluxes	
• Hot	Fluxes	
• Demos	
• Basic	opera+ons	
• Controlling	emission	rate	
• A@aching	to	a	feed	
1
What is Reac0ve?
• Alternate	programming	paradigm	–	think	in	terms	of	streams	
instead	of	objects.		
• Reac+ve	Streams	–high-performance,	asynch	stream	processing	
non-blocking	back	pressure.	
• Declara+ve	tools	for	concise,	error	free	code,	especially	under	
high	load	and	concurrency.	
• Simplify	clean	coding	of	asynchronous	event	driven	
programming.	
• The	good	news	is,	it	does	not	change	much	from	language	to	
language.	
2
CloJure	
Cross language support
Java	 	 	 	 		
3	
my_observable	
		.map(Name::firstName)	
		.map(String::toLowerCase)	
		.filter(x	->	x.startsWith("bob"))	
		.dis+nct()	
		.toList()
4	
Problem:	Merging	many	requests	
NetflixAPI
Server		Request	Latency	 Network	Latency	
Device	
Server
Maven Dependencies
5	
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-test</artifactId>
</dependency>
•  Everything	is	a	stream	of	messages	
•  Flux	emits	event	messages	(“Observable”	in	rx-java	land)	
•  Subscribers	consume	messages	
•  Fluxes	are	immutable	(opera+ons	return	new	Fluxes)	
Implements	Publisher	
Emits	messages	from:	
•  Remote	services	
•  Data	feeds	
•  Mouse	events…	
												Subscriber	
Consumes	pushed	messages:	
•  onNext()	
•  onError()	
•  onComplete()	
Basic Model
6	
Message	stream	
Examples:	
•  Events	
•  Query	results	
•  Computa+ons	
•  Even	errors!	
Flux	 Subscriber
onNext()	
onComplete()	 onError()	
(onError()	and	onComplete()	are	terminal	opera+ons.)	
A	Subscriber	receives	noFficaFons:!
public interface Subscriber<T>!
void onNext(T t); void
onComplete(); !
void onError(Throwable t); void
onSubscribe(); !
	
!
7
…AIaching	a	Subscriber	
8	
flux.subscribe(
v -> handleHappyPath(v), // happy path
error -> handleError(error), // error handler

// (optional)
() -> handle(“Done") // completion
// (optional)
);
Transform and combine Flux streams
Flux	
				.filter(…)	
				.subscribe(…)	
9	
• Or	even	
Flux	
		
• Or	
Flux	
				.map(…)	
				.subscribe(…)	
Each	transforma+on	returns	a	new	resultant	Flux.	
etc.,	etc.,	etc.	
.filter(…)	
.map(…)	
.subscribe(…)	
.filter(…)	
.map(…)	
.doOnNext(System.out::println)	
.subscribe(…)
MARBLE DIAGRAMS
h@p://rxmarbles.com/	Interac+ve	marble	diagrams	
10
Combine Fluxes to produce new Fluxes
Examples: 	merge	–	merges	elements	as	they	arrive.	
	 	zip	–	combines	elements	in	sequence.	
	 	firstEmikng	–	returns	the	first	stream	to	emit	an	element.	
11	
• Methods take one Flux as input and return another Flux.
Crea0ng a Flux
Flux.just(value)	–	Creates	instance	that	emits	the	supplied	
value(s).	
Flux.fromIterable/fromArray(values)	–	
Accepts	Collec+on<T>	or	array,	creates	a	Flux<T>,	which	
emits	the	values	of	the	collec+on.	
Flux.range(i,	n)	–	Produces	n	consecu+ve	integers	star+ng	
from	i.	
Flux.interval(Dura+on.ofSeconds(n))	–	Emits	a	count,	every	
n	+me	units	
12	
etc.	etc.	etc.
Transforming Fluxes
Methods take one stream as input and return another stream.
•  Flux.take(n) – Takes first n elements only.
•  Flux.skip(n) – Skips first n elements, then takes the rest
•  Flux.distinct() – Returns a new Flux with duplicates eliminated.
•  Flux.distinctUntilChanged() – Eliminates consecutive duplicates.
•  Flux.filter((x)->condition()) – Retains elements matching filter condition.
•  Flux.map(Some::mapper) – Replaces elements with other elements.
•  Flux.flatMap(Some::mapper) – Replaces elements with Fluxes.
13
Time Filtering
thro@leFirst()	–	Takes	only	the	first	amer	every	n	+me	units	
thro@leLast()	–	Takes	only	the	last	element	amer	every	n	+me	units	
debounce()	–	Takes	only	the	last	event	of	each	set	in	the	specified	+me.	
+meout()	–	Issues	an	excep+on	if	no	events	before	+meout	
14	
Select elements based on timing
debounce
Difference between Java Stream API and Reac0ve
15	
Java	Streams	 ReacFve	Streams	
Pull	based	 Push	based	
Basically	a	way	to	iterate	
collec+ons	declara+vely	
A@ach	to	real-+me	feeds	
Generally	synchronous	data	 Real-+me,	concurrency,	flow	control	
Streams	can	only	be	used	once		 Reac+ve	streams	are	highly	reusable	
No	control	of	+ming	 Control	back-pressure	strategies	
No	composi+on	of	streams	 Advanced	composi+on	and	
transforma+on	
Finite	amount	of	data	 Data	sizes	from	zero	to	infinity
Concurrency
• Observers	are	synchronous;	concurrent	calls	are	
handled	in	sequence	
• No	need	to	code	defensively	for	concurrency	
• And	no	loss	in	latency	due	to	synchroniza+on	
16
Asynchronous Streams
Built	in	support	for	concurrent	publishers	and	subscribers	
•  Flux.observeOn(scheduler)	–	Specifies	the	thread	for	the	Observer	
•  Flux.subscribeOn(scheduler)	–	Specifies	the	thread	for	the	Subscriber	
Types	of	schedulers	
•  Schedulers.immediate()	–	Parks	current	process	and	uses	current	thread	
•  Schedulers.computa2on()	–	The	system-assigned	computa+on	thread	
•  Schedulers.io()	–	The	system-assigned	IO	thread	
•  Schedulers.trampoline()	–	Uses	the	current	thread,	once	it	is	done	here	
•  Schedulers.newThread()	–	Uses	a	new	thread	
•  Schedulers.from(Executor)	–	On	the	named	executor	
17
Cold Fluxes and Hot Fluxes
18	
• Cold	Fluxes		
• Won’t	begin	pumping	un+l	a	subscriber	is	a@ached.		
• Each	subscriber	receives	all	of	the	events,	beginning	
from	the	historical	first.	
• Hot	Fluxes	
• Generally	read	live	data,	for	example	data	feeds	or	
mouse	movements.	
• Begin	pumping	on	connec+on.	
• Each	subscriber	gets	the	latest	feeds	as	they	pump
Addi0onal Cold Fluxes (for Development)
• Flux.empty()	–	Completes	on	the	first	subscrip+on,	without	
emikng	any	values.	
• Flux.never()	–	Emits	no		values	and	never	completes.	
• Flux.error()	–	Emits	an	onError()	no+fica+on	immediately	on	
every	subscriber.	No	other	values	are	emi@ed.	
• Flux.doOnNext()	–	Diagnos+cs	
19
Crea0ng Hot Fluxes (Flowables)
20	
o  Call “publish” on a cold Flux

ConnectableFlux<Long> hotFlux = 
coldFlux.publish();

o  Call “connect” to start pumping, with or without subscribers

hotFlux.connect();	
	

hotFlux.subscribe(

val -> System.out.println("Subscriber >> " +val));
Introducing Reac0ve Programming
Pivotal’s Reactor
Victor	Grazi	
GMIT	Core	IT	
Demo
Victor	Grazi	
GMIT	Core	IT	
Introducing Reac0ve Programming
Pivotal’s Reactor
Victor	Grazi	
GMIT	Core	IT	
?	 ?	 ?	
Q&A	
?
Coun0ng le[ers
23	
List<String> words = Arrays.asList(
"the",
"quick",
"brown",
"fox",
"jumps",
"over",
"the",
"lazy",
"dog"
);
Flux<Integer> lines = Flux.range(1, Integer.MAX_VALUE);
Flux<String> wordsFlux = Flux.fromIterable(words);
wordsFlux
.flatMap(word -> Flux.fromArray(word.split("")))
.distinct()
.sort()
.zipWith(lines, (word, line) -> line + " " + word)
.subscribe(System.out::println);
Metronome example
24	
Flux<Long> fast = Flux.interval(Duration.ofSeconds(1));
Flux<Long> slow = Flux.interval(Duration.ofSeconds(3));
Flux<Long> clock = Flux.merge(
fast.filter(t -> isFastTime()),
slow.filter(t -> isSlowTime())
);
Flux<LocalDateTime> dateEmitter = Flux.interval(Duration.ofSeconds(1))
.map(t -> LocalDateTime.now());
Flux<LocalDateTime> localDateTimeFlux = clock.withLatestFrom(dateEmitter, (tick, date) -> date);
localDateTimeFlux.subscribe(t ->
System.out.println(t.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"))));
Emi[er sample
25	
SomeFeed<PriceTick> feed = new SomeFeed<>();
Flux<Object> priceFlux = Flux.create(emitter ->
{
SomeListener l = new SomeListener() {
@Override
public void priceTick(PriceTick event) {
emitter.next(event);
}
@Override
public void error(Throwable throwable) {
emitter.error(throwable);
}
};
feed.register(l);
}, FluxSink.OverflowStrategy.LATEST);
ConnectableFlux<Object> connectableFlux = priceFlux.publish();
connectableFlux.connect();
connectableFlux.subscribe(System.out::println);

More Related Content

What's hot (20)

PDF
6. Utilización del modelo de objetos del documento (DOM)
Laura Folgado Galache
 
PDF
HTTP Request Smuggling via higher HTTP versions
neexemil
 
PPSX
Exception Handling
Reddhi Basu
 
PDF
Java threads
Prabhakaran V M
 
PPTX
Web Hacking With Burp Suite 101
Zack Meyers
 
PPTX
JRE , JDK and platform independent nature of JAVA
Mehak Tawakley
 
PDF
Spring boot jpa
Hamid Ghorbani
 
PPTX
Cusomizing Burp Suite - Getting the Most out of Burp Extensions
August Detlefsen
 
PPT
Semaphores OS Basics
Shijin Raj P
 
PDF
Frans Rosén Keynote at BSides Ahmedabad
Security BSides Ahmedabad
 
PPTX
Object Oriented Programing JAVA presentaion
Pritom Chaki
 
PDF
Exception handling and logging best practices
Angelin R
 
PPSX
Java Multi-threading programming
DrRajeshreeKhande
 
PDF
웹서버 부하테스트 실전 노하우
IMQA
 
PPTX
Exception handling in Java
Ankit Rai
 
PPTX
Abstraction java
MahinImran
 
PDF
Project Reactor Now and Tomorrow
VMware Tanzu
 
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Soroush Dalili
 
PDF
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
Frans Rosén
 
PPTX
CSRF Attack and Its Prevention technique in ASP.NET MVC
Suvash Shah
 
6. Utilización del modelo de objetos del documento (DOM)
Laura Folgado Galache
 
HTTP Request Smuggling via higher HTTP versions
neexemil
 
Exception Handling
Reddhi Basu
 
Java threads
Prabhakaran V M
 
Web Hacking With Burp Suite 101
Zack Meyers
 
JRE , JDK and platform independent nature of JAVA
Mehak Tawakley
 
Spring boot jpa
Hamid Ghorbani
 
Cusomizing Burp Suite - Getting the Most out of Burp Extensions
August Detlefsen
 
Semaphores OS Basics
Shijin Raj P
 
Frans Rosén Keynote at BSides Ahmedabad
Security BSides Ahmedabad
 
Object Oriented Programing JAVA presentaion
Pritom Chaki
 
Exception handling and logging best practices
Angelin R
 
Java Multi-threading programming
DrRajeshreeKhande
 
웹서버 부하테스트 실전 노하우
IMQA
 
Exception handling in Java
Ankit Rai
 
Abstraction java
MahinImran
 
Project Reactor Now and Tomorrow
VMware Tanzu
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Soroush Dalili
 
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
Frans Rosén
 
CSRF Attack and Its Prevention technique in ASP.NET MVC
Suvash Shah
 

Similar to Reactive programming with Pivotal's reactor (20)

PPTX
Reactive solutions using java 9 and spring reactor
OrenEzer1
 
PDF
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
 
PDF
Reactive Applications in Java
Alexander Mrynskyi
 
PDF
reactive_programming_for_java_developers.pdf
Akshitkumar437417
 
PDF
Guide to Spring Reactive Programming using WebFlux
Inexture Solutions
 
PDF
Reactive Applications with Apache Pulsar and Spring Boot
VMware Tanzu
 
PDF
IPT Reactive Java IoT Demo - BGOUG 2018
Trayan Iliev
 
PDF
Let’s go reactive with JAVA
Tech Triveni
 
PPTX
Reactive programming for java developers
Constantin Popa
 
PDF
Reactive&amp;reactor
Geng-Dian Huang
 
PDF
Spring 5 Webflux - Advances in Java 2018
Trayan Iliev
 
PPTX
From Web to Flux @DevoxxBE 2023.pptx
Victor Rentea
 
PDF
Workshop: Event-sourced system through Reactive Streams
sterkje
 
PPTX
Workshop: Event-sourced system through Reactive Streams
Kristof Van Sever
 
PDF
Microservices with Spring 5 Webflux - jProfessionals
Trayan Iliev
 
PDF
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
Toshiaki Maki
 
PPTX
From Streams to Reactive Streams
Oleg Tsal-Tsalko
 
PDF
Reactive systems
Naresh Chintalcheru
 
PDF
Springone2gx 2014 Reactive Streams and Reactor
Stéphane Maldini
 
PPTX
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Codemotion
 
Reactive solutions using java 9 and spring reactor
OrenEzer1
 
Reactive Programming in Java and Spring Framework 5
Richard Langlois P. Eng.
 
Reactive Applications in Java
Alexander Mrynskyi
 
reactive_programming_for_java_developers.pdf
Akshitkumar437417
 
Guide to Spring Reactive Programming using WebFlux
Inexture Solutions
 
Reactive Applications with Apache Pulsar and Spring Boot
VMware Tanzu
 
IPT Reactive Java IoT Demo - BGOUG 2018
Trayan Iliev
 
Let’s go reactive with JAVA
Tech Triveni
 
Reactive programming for java developers
Constantin Popa
 
Reactive&amp;reactor
Geng-Dian Huang
 
Spring 5 Webflux - Advances in Java 2018
Trayan Iliev
 
From Web to Flux @DevoxxBE 2023.pptx
Victor Rentea
 
Workshop: Event-sourced system through Reactive Streams
sterkje
 
Workshop: Event-sourced system through Reactive Streams
Kristof Van Sever
 
Microservices with Spring 5 Webflux - jProfessionals
Trayan Iliev
 
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
Toshiaki Maki
 
From Streams to Reactive Streams
Oleg Tsal-Tsalko
 
Reactive systems
Naresh Chintalcheru
 
Springone2gx 2014 Reactive Streams and Reactor
Stéphane Maldini
 
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Codemotion
 
Ad

More from VMware Tanzu (20)

PDF
Spring into AI presented by Dan Vega 5/14
VMware Tanzu
 
PDF
What AI Means For Your Product Strategy And What To Do About It
VMware Tanzu
 
PDF
Make the Right Thing the Obvious Thing at Cardinal Health 2023
VMware Tanzu
 
PPTX
Enhancing DevEx and Simplifying Operations at Scale
VMware Tanzu
 
PDF
Spring Update | July 2023
VMware Tanzu
 
PPTX
Platforms, Platform Engineering, & Platform as a Product
VMware Tanzu
 
PPTX
Building Cloud Ready Apps
VMware Tanzu
 
PDF
Spring Boot 3 And Beyond
VMware Tanzu
 
PDF
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
VMware Tanzu
 
PDF
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
VMware Tanzu
 
PDF
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
VMware Tanzu
 
PPTX
tanzu_developer_connect.pptx
VMware Tanzu
 
PDF
Tanzu Virtual Developer Connect Workshop - French
VMware Tanzu
 
PDF
Tanzu Developer Connect Workshop - English
VMware Tanzu
 
PDF
Virtual Developer Connect Workshop - English
VMware Tanzu
 
PDF
Tanzu Developer Connect - French
VMware Tanzu
 
PDF
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
VMware Tanzu
 
PDF
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
VMware Tanzu
 
PDF
SpringOne Tour: The Influential Software Engineer
VMware Tanzu
 
PDF
SpringOne Tour: Domain-Driven Design: Theory vs Practice
VMware Tanzu
 
Spring into AI presented by Dan Vega 5/14
VMware Tanzu
 
What AI Means For Your Product Strategy And What To Do About It
VMware Tanzu
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
VMware Tanzu
 
Enhancing DevEx and Simplifying Operations at Scale
VMware Tanzu
 
Spring Update | July 2023
VMware Tanzu
 
Platforms, Platform Engineering, & Platform as a Product
VMware Tanzu
 
Building Cloud Ready Apps
VMware Tanzu
 
Spring Boot 3 And Beyond
VMware Tanzu
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
VMware Tanzu
 
tanzu_developer_connect.pptx
VMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
VMware Tanzu
 
Tanzu Developer Connect Workshop - English
VMware Tanzu
 
Virtual Developer Connect Workshop - English
VMware Tanzu
 
Tanzu Developer Connect - French
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
VMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
VMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
VMware Tanzu
 
Ad

Recently uploaded (20)

PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Import Data Form Excel to Tally Services
Tally xperts
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 

Reactive programming with Pivotal's reactor