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

PDF
Project Reactor Now and Tomorrow
PDF
Reactor in Action
PPTX
Designing, Implementing, and Using Reactive APIs
PDF
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
PDF
RxJava - introduction & design
PDF
Reactive programming with Rxjava
PDF
Understanding and Extending Prometheus AlertManager
PDF
Asynchronous stream processing with Akka Streams
Project Reactor Now and Tomorrow
Reactor in Action
Designing, Implementing, and Using Reactive APIs
Servlet or Reactive Stacks: The Choice is Yours. Oh No...The Choice is Mine!
RxJava - introduction & design
Reactive programming with Rxjava
Understanding and Extending Prometheus AlertManager
Asynchronous stream processing with Akka Streams

What's hot (20)

PDF
Designing for Distributed Systems with Reactor and Reactive Streams
PPTX
Introduction to Reactive Java
PDF
Reactive Programming in Java and Spring Framework 5
PDF
Developing Real-Time Data Pipelines with Apache Kafka
PDF
rx-java-presentation
PPTX
Reactive Programming in Java 8 with Rx-Java
PDF
Streaming all the things with akka streams
PPTX
The Future of Apache Storm
PDF
How to monitor your micro-service with Prometheus?
PDF
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
PDF
Akka-chan's Survival Guide for the Streaming World
PDF
Reactive Streams 1.0 and Akka Streams
PDF
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
PPTX
Prometheus - Intro, CNCF, TSDB,PromQL,Grafana
PDF
Microservices with Netflix OSS and Spring Cloud
PDF
Akka streams - Umeå java usergroup
PDF
OpenStack Tempest and REST API testing
PDF
Let the alpakka pull your stream
PPTX
Modern Java Workshop
PDF
Modern app programming with RxJava and Eclipse Vert.x
Designing for Distributed Systems with Reactor and Reactive Streams
Introduction to Reactive Java
Reactive Programming in Java and Spring Framework 5
Developing Real-Time Data Pipelines with Apache Kafka
rx-java-presentation
Reactive Programming in Java 8 with Rx-Java
Streaming all the things with akka streams
The Future of Apache Storm
How to monitor your micro-service with Prometheus?
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Akka-chan's Survival Guide for the Streaming World
Reactive Streams 1.0 and Akka Streams
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
Prometheus - Intro, CNCF, TSDB,PromQL,Grafana
Microservices with Netflix OSS and Spring Cloud
Akka streams - Umeå java usergroup
OpenStack Tempest and REST API testing
Let the alpakka pull your stream
Modern Java Workshop
Modern app programming with RxJava and Eclipse Vert.x
Ad

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

PPTX
Reactive solutions using java 9 and spring reactor
PDF
Reactive Applications in Java
PDF
reactive_programming_for_java_developers.pdf
PDF
Guide to Spring Reactive Programming using WebFlux
PDF
Reactive Applications with Apache Pulsar and Spring Boot
PDF
IPT Reactive Java IoT Demo - BGOUG 2018
PDF
Let’s go reactive with JAVA
PPTX
Reactive programming for java developers
PDF
Reactive&amp;reactor
PDF
Spring 5 Webflux - Advances in Java 2018
PPTX
From Web to Flux @DevoxxBE 2023.pptx
PDF
Workshop: Event-sourced system through Reactive Streams
PPTX
Workshop: Event-sourced system through Reactive Streams
PDF
Microservices with Spring 5 Webflux - jProfessionals
PDF
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
PPTX
From Streams to Reactive Streams
PDF
Reactive systems
PDF
Springone2gx 2014 Reactive Streams and Reactor
PPTX
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
PDF
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive solutions using java 9 and spring reactor
Reactive Applications in Java
reactive_programming_for_java_developers.pdf
Guide to Spring Reactive Programming using WebFlux
Reactive Applications with Apache Pulsar and Spring Boot
IPT Reactive Java IoT Demo - BGOUG 2018
Let’s go reactive with JAVA
Reactive programming for java developers
Reactive&amp;reactor
Spring 5 Webflux - Advances in Java 2018
From Web to Flux @DevoxxBE 2023.pptx
Workshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive Streams
Microservices with Spring 5 Webflux - jProfessionals
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
From Streams to Reactive Streams
Reactive systems
Springone2gx 2014 Reactive Streams and Reactor
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
Ad

More from VMware Tanzu (20)

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

Recently uploaded (20)

PPTX
Trending Python Topics for Data Visualization in 2025
PDF
Guide to Food Delivery App Development.pdf
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
Microsoft Office 365 Crack Download Free
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PDF
AI Guide for Business Growth - Arna Softech
PPTX
Download Adobe Photoshop Crack 2025 Free
PDF
E-Commerce Website Development Companyin india
PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Website Design Services for Small Businesses.pdf
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Trending Python Topics for Data Visualization in 2025
Guide to Food Delivery App Development.pdf
GSA Content Generator Crack (2025 Latest)
Microsoft Office 365 Crack Download Free
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
AI Guide for Business Growth - Arna Softech
Download Adobe Photoshop Crack 2025 Free
E-Commerce Website Development Companyin india
"Secure File Sharing Solutions on AWS".pptx
Autodesk AutoCAD Crack Free Download 2025
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
Full-Stack Developer Courses That Actually Land You Jobs
Advanced SystemCare Ultimate Crack + Portable (2025)
MCP Security Tutorial - Beginner to Advanced
CCleaner 6.39.11548 Crack 2025 License Key
iTop VPN Crack Latest Version Full Key 2025
Website Design Services for Small Businesses.pdf
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...

Reactive programming with Pivotal's reactor