SlideShare a Scribd company logo
Reactive Spring 5
Reactive Programming with Spring WebFlux and Spring Data
Corneil du Plessis
About Me
• Working as Programmer since 1985
• Smallest to very large systems.
• Cobol, Fortan, Pascal, Algol, C/C++, Java, JavaScript, Groovy,
Python, Scala, Kotlin and more.
• Scientific instrumentation, Sports event management, Mining,
Banking, Treasury and Insurance.
• Software Architect (with a preference for coding)
A definition
reactive programming is an asynchronous programming
paradigm concerned with data streams and the propagation of
change
Wikipedia
Reactive Manifesto
• Responsive
• Resilient
• Elastic
• Message Driven
Why reactive programming?
• Handle back-pressure
• Communicate change
• Scalability
• Performance
• Reliability
Reactive Programming Models
• Windows API
• JVM Based
• NIO
• LMAX Disruptor
• Akka Actor Model
• JavaScript
• AJAX
• Promises
• jQuery
• Angular
• React
• FRP – Functional Reactive
Programming
• map, reduce, filter
• Languages not limited to:
• Scala
• Kotlin
• Haskell
• Elm
• Groovy
• JavaScript
• Java 8
Road to Reactive Spring
• RxJava – 2011-2012 by Netflix
• Project Reactor – 2013 by Pivotal
• Reactive Streams Specification – 2014 collaboration by
Netflix, Pivotal, Red Hat, Twitter, Typesafe and more.
• reactor-spring
• Spring 5
Implementing Technologies
HttpHander / WebHander API
• Netty
• Undertow
• Tomcat with Servlet 3.1
• Jetty with Servlet 3.1
Reactive Databases
• MongoDB Reactive Streams
Driver
• Reactive Cassandra (RxJava)
• Lettuce (Reactive Streams for
Redis)
• Reactive Couchbase.
Reactive Streams specification
• Publisher
• Subscriber
• Subscription
• Processor
Reactive Streams – Sequence Diagrams
Subscribe Publish
Project Reactor
• Implements Reactive Streams specification
• Influenced by RxJava
• Influenced by Java 8 Streams
• Improved Developer Experience
• Mono<T> - 0 or One
• Flux<T> - 0 or More
Project Reactor - Mono
static <T> Mono<T> just(T data);
static <T> Mono<T> fromFuture(
CompleteableFuture<? extends T>);
Mono<T> log(String category);
T block();
T block(Duration timeout);
map, flatMap, filter
Project Reactor - Flux
static <T> Flux<T> just(T data);
static <T> Flux<T> just(T … data);
static <T> Flux<T> fromStream(Stream<T> s);
static <T> Flux<T> fromIterable<Iterable<T> i);
Flux<T> log(String category);
static <T> Mono<List<T>> collectList();
Mono<T> next();
Iterable<T> toIterable();
Stream<T> toStream();
map, flatMap, filter, reduce
Reactive Spring WebFlux
• Annotated Controllers
• @Controller or @RestController
• @RequestMapping / @GetMapping / @PostMapping etc.
• Flux instead of Collection
• Functional Endpoints
• Router Function
• Handler Function
• HandlerFilter Function
Spring MVC
@RestController
public class HistoryController {
private HistoryInterface locHist;
public HistoryController(HistoryInterface locHist) {
this. locHist = locHist;
}
@GetMapping(path = "/last30days")
public Collection<LocationHistory> find(
@RequestParam("startDate") Date startDate,
@RequestParam("endDate") Date endDate) {
return locHist.find(startDate, endDate);
}
}
Reactive Spring WebFlux
@RestController
public class HistoryController {
private HistoryInterface locHist;
public HistoryController(HistoryInterface locHist) {
this. locHist = locHist;
}
@GetMapping(path = "/last30days")
public Flux<LocationHistory> find(
@RequestParam("startDate") Date startDate,
@RequestParam("endDate") Date endDate) {
return locHist.find(startDate, endDate);
}
}
Reactive Spring WebFlux (Functional
Endpoint)
public class HistoryHandler {
private HistoryInterface locHist;
public History HistoryHandler(
HistoryInterface locHist) {
this. locHist = locHist;
}
public Mono<ServerResponse> find(ServerRequest request) {
Date startDate = DateUtils.from(request.queryParam("startDate"));
Date endDate = DateUtils.from(request.queryParam("endDate"));
return ServerResponse.ok()
.contentType(APPLICATION_JSON)
.body(locHist.find(startDate, endDate), LocationHistory.class);
}
}
Reactive Spring WebFlux (Functional
Endpoint)
@Configuration
@EnableWebFlux
public class HistoryConfiguration {
@Autowire
private HistoryHandler histHandler;
@Bean
RouterFunction<ServerResponse> router() {
return route(GET("/last30days")
.and(accept(APPLICATION_JSON)), histHandler::find);
}
}
Spring Data
public interface LocationHistoryRepository
extends CrudRepository<LocationHistory, String> {
Collection<LocationHistory> findByTimestampBetween(
Date s, Date e);
}
Reactive Spring Data
public interface LocationHistoryRepository
extends ReactiveCrudRepository<LocationHistory, String> {
Flux<LocationHistory> findByTimestampBetween(
Date s, Date e);
}
Spring Data JPA
• Spring Data JPA does not have Reactive Support.
• Streams will provide best experience until reactive JDBC and JPA
is available.
// Repository method
Stream<LocationHistory> findByDateBetween(
Date startDate, Date endDate);
// Service method
return Flux.fromStream(repository.findByDateBetween(s,e));
Demo
Non-reactive
• Spring Boot 1.5.8
• Spring MVC
• Spring Data MongoDB
Reactive
• Spring Boot 2.0 RC
• Spring WebFlux
• Spring Data Reactive
MongoDB
Call timing
Non-reactive
• 0.000 >> controller
• 0.000 >> service
• 0.409 << service
• 0.409 << controller
Reactive
• 0.000 >> controller
• 0.000 >> service
• 0.001 << service
• 0.001 << controller
Synchronous process
Asynchronous process
Network timing
Non-reactive
Type Time
Name lookup 0.004
Connect 0.005
Pre transfer 0.005
Start Transfer 0.419
Total 0.532
Reactive
Type Time
Name lookup 0.004
Connect 0.005
Pre transfer 0.005
Start Transfer 0.385
Total 0.425
More aspects of Reactive Programming
• Error handling
• Back pressure
• Retry
• Timeouts
• Transactions
Thoughts on Reactive Spring
• Pros
• Great documentation
• Preserves program structure
• Safer concurrency
• Simpler abstraction than RxJava without sacrificing the power.
• Facilitates good practice
• Kotlin support in Core
• Cons
• Debugging complexity
• Could not find any other negative comments
See Also
• ReactiveX
• Languages
• RxJava
• RxKotlin
• RxGroovy
• RxClojure
• RxSwift
• Rx.Net (C#) and more…
• Platforms
• RxAndroid
• RxCocoa
• RxNetty
• Akka & Akka Streams
• Ratpack
• Vert.x
• Play Framework
• Languages
• Reactor Scala Extensions
• Reactor Kotlin Extensions (now in core)
• Messaging Communication
• Reactor Kafka
• Reactor RabbitMQ
• Reactor Aeron
• Reactor Netty
Finally
• Source - https://github.com/corneil/reactive-spring-5
• Slides - https://www.slideshare.net/CorneilduPlessis/reactive-
spring-5
• Resources
• Project Reactor Site - https://projectreactor.io/
• David Karnok's Blog - http://akarnokd.blogspot.co.za/
Questions?

More Related Content

What's hot

Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
Trayan Iliev
 
Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9
Trayan Iliev
 
Reactive Microservice And Spring5
Reactive Microservice And Spring5Reactive Microservice And Spring5
Reactive Microservice And Spring5
Jay Lee
 
Unify Enterprise Data Processing System Platform Level Integration of Flink a...
Unify Enterprise Data Processing System Platform Level Integration of Flink a...Unify Enterprise Data Processing System Platform Level Integration of Flink a...
Unify Enterprise Data Processing System Platform Level Integration of Flink a...
Flink Forward
 
Introducing Arc: A Common Intermediate Language for Unified Batch and Stream...
Introducing Arc:  A Common Intermediate Language for Unified Batch and Stream...Introducing Arc:  A Common Intermediate Language for Unified Batch and Stream...
Introducing Arc: A Common Intermediate Language for Unified Batch and Stream...
Flink Forward
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
Jay Lee
 
Universal metrics with Apache Beam
Universal metrics with Apache BeamUniversal metrics with Apache Beam
Universal metrics with Apache Beam
Etienne Chauchot
 
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Dan Halperin
 
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
Event sourcing  - what could possibly go wrong ? Devoxx PL 2021Event sourcing  - what could possibly go wrong ? Devoxx PL 2021
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
Andrzej Ludwikowski
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing data
DataWorks Summit/Hadoop Summit
 
The Evolution of (Open Source) Data Processing
The Evolution of (Open Source) Data ProcessingThe Evolution of (Open Source) Data Processing
The Evolution of (Open Source) Data Processing
Aljoscha Krettek
 
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward
 
Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015
Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015
Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015
Robert Metzger
 
Diving into the Deep End - Kafka Connect
Diving into the Deep End - Kafka ConnectDiving into the Deep End - Kafka Connect
Diving into the Deep End - Kafka Connect
confluent
 
Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15
Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15
Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15
Vasia Kalavri
 
Moon soo Lee – Data Science Lifecycle with Apache Flink and Apache Zeppelin
Moon soo Lee – Data Science Lifecycle with Apache Flink and Apache ZeppelinMoon soo Lee – Data Science Lifecycle with Apache Flink and Apache Zeppelin
Moon soo Lee – Data Science Lifecycle with Apache Flink and Apache Zeppelin
Flink Forward
 
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkMaximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Flink Forward
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Kaxil Naik
 
Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...
Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...
Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...
Flink Forward
 
Pulsar connector on flink 1.14
Pulsar connector on flink 1.14Pulsar connector on flink 1.14
Pulsar connector on flink 1.14
宇帆 盛
 

What's hot (20)

Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
 
Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9
 
Reactive Microservice And Spring5
Reactive Microservice And Spring5Reactive Microservice And Spring5
Reactive Microservice And Spring5
 
Unify Enterprise Data Processing System Platform Level Integration of Flink a...
Unify Enterprise Data Processing System Platform Level Integration of Flink a...Unify Enterprise Data Processing System Platform Level Integration of Flink a...
Unify Enterprise Data Processing System Platform Level Integration of Flink a...
 
Introducing Arc: A Common Intermediate Language for Unified Batch and Stream...
Introducing Arc:  A Common Intermediate Language for Unified Batch and Stream...Introducing Arc:  A Common Intermediate Language for Unified Batch and Stream...
Introducing Arc: A Common Intermediate Language for Unified Batch and Stream...
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
 
Universal metrics with Apache Beam
Universal metrics with Apache BeamUniversal metrics with Apache Beam
Universal metrics with Apache Beam
 
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
 
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
Event sourcing  - what could possibly go wrong ? Devoxx PL 2021Event sourcing  - what could possibly go wrong ? Devoxx PL 2021
Event sourcing - what could possibly go wrong ? Devoxx PL 2021
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing data
 
The Evolution of (Open Source) Data Processing
The Evolution of (Open Source) Data ProcessingThe Evolution of (Open Source) Data Processing
The Evolution of (Open Source) Data Processing
 
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
Flink Forward Berlin 2017: Piotr Wawrzyniak - Extending Apache Flink stream p...
 
Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015
Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015
Architecture of Flink's Streaming Runtime @ ApacheCon EU 2015
 
Diving into the Deep End - Kafka Connect
Diving into the Deep End - Kafka ConnectDiving into the Deep End - Kafka Connect
Diving into the Deep End - Kafka Connect
 
Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15
Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15
Large-scale graph processing with Apache Flink @GraphDevroom FOSDEM'15
 
Moon soo Lee – Data Science Lifecycle with Apache Flink and Apache Zeppelin
Moon soo Lee – Data Science Lifecycle with Apache Flink and Apache ZeppelinMoon soo Lee – Data Science Lifecycle with Apache Flink and Apache Zeppelin
Moon soo Lee – Data Science Lifecycle with Apache Flink and Apache Zeppelin
 
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkMaximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
 
Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...
Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...
Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey...
 
Pulsar connector on flink 1.14
Pulsar connector on flink 1.14Pulsar connector on flink 1.14
Pulsar connector on flink 1.14
 

Similar to Reactive Spring 5

Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering
Massimo Sgrelli
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
Kevin Webber
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
Stéphane Maldini
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3
takezoe
 
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project ReactorReactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
VMware Tanzu
 
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDKBigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
nagachika t
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
Markus Eisele
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EE
J On The Beach
 
Evolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.jsEvolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.js
Steve Jamieson
 
Enterprise Software Architecture styles
Enterprise Software Architecture stylesEnterprise Software Architecture styles
Enterprise Software Architecture styles
Araf Karsh Hamid
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19
Markus Eisele
 
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at ScaleFiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
Evan Chan
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
allegro.tech
 
The Evolution of a Relational Database Layer over HBase
The Evolution of a Relational Database Layer over HBaseThe Evolution of a Relational Database Layer over HBase
The Evolution of a Relational Database Layer over HBase
DataWorks Summit
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
Malam Team
 
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
Intro to Apache Apex - Next Gen Platform for Ingest and TransformIntro to Apache Apex - Next Gen Platform for Ingest and Transform
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
Apache Apex
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lightbend
 
Parasoft Testing anything, any time with containerized service virtualization
Parasoft Testing anything, any time with containerized service virtualizationParasoft Testing anything, any time with containerized service virtualization
Parasoft Testing anything, any time with containerized service virtualization
ChantalWauters
 
SQL on everything, in memory
SQL on everything, in memorySQL on everything, in memory
SQL on everything, in memory
Julian Hyde
 

Similar to Reactive Spring 5 (20)

Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
 
JavaOne_2010
JavaOne_2010JavaOne_2010
JavaOne_2010
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3
 
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project ReactorReactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
 
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDKBigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EE
 
Evolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.jsEvolution of a cloud start up: From C# to Node.js
Evolution of a cloud start up: From C# to Node.js
 
Enterprise Software Architecture styles
Enterprise Software Architecture stylesEnterprise Software Architecture styles
Enterprise Software Architecture styles
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19
 
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at ScaleFiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
The Evolution of a Relational Database Layer over HBase
The Evolution of a Relational Database Layer over HBaseThe Evolution of a Relational Database Layer over HBase
The Evolution of a Relational Database Layer over HBase
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
Intro to Apache Apex - Next Gen Platform for Ingest and TransformIntro to Apache Apex - Next Gen Platform for Ingest and Transform
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
 
Parasoft Testing anything, any time with containerized service virtualization
Parasoft Testing anything, any time with containerized service virtualizationParasoft Testing anything, any time with containerized service virtualization
Parasoft Testing anything, any time with containerized service virtualization
 
SQL on everything, in memory
SQL on everything, in memorySQL on everything, in memory
SQL on everything, in memory
 

More from Corneil du Plessis

Sweet Streams (Are made of this)
Sweet Streams (Are made of this)Sweet Streams (Are made of this)
Sweet Streams (Are made of this)
Corneil du Plessis
 
Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Cloud Native Applications for Cloud Foundry using Spring Cloud : A WorkshopCloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Corneil du Plessis
 
QueryDSL - Lightning Talk
QueryDSL - Lightning TalkQueryDSL - Lightning Talk
QueryDSL - Lightning Talk
Corneil du Plessis
 
Enhancements in Java 9 Streams
Enhancements in Java 9 StreamsEnhancements in Java 9 Streams
Enhancements in Java 9 Streams
Corneil du Plessis
 
Empathic API-Design
Empathic API-DesignEmpathic API-Design
Empathic API-Design
Corneil du Plessis
 
Performance Comparison JVM Languages
Performance Comparison JVM LanguagesPerformance Comparison JVM Languages
Performance Comparison JVM Languages
Corneil du Plessis
 
Microservices Patterns and Anti-Patterns
Microservices Patterns and Anti-PatternsMicroservices Patterns and Anti-Patterns
Microservices Patterns and Anti-Patterns
Corneil du Plessis
 
Consume Spring Data Rest with Angularjs
Consume Spring Data Rest with AngularjsConsume Spring Data Rest with Angularjs
Consume Spring Data Rest with Angularjs
Corneil du Plessis
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
Corneil du Plessis
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
Corneil du Plessis
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring Data
Corneil du Plessis
 
Data repositories
Data repositoriesData repositories
Data repositories
Corneil du Plessis
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
Corneil du Plessis
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10minCorneil du Plessis
 

More from Corneil du Plessis (15)

Sweet Streams (Are made of this)
Sweet Streams (Are made of this)Sweet Streams (Are made of this)
Sweet Streams (Are made of this)
 
Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Cloud Native Applications for Cloud Foundry using Spring Cloud : A WorkshopCloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
 
QueryDSL - Lightning Talk
QueryDSL - Lightning TalkQueryDSL - Lightning Talk
QueryDSL - Lightning Talk
 
Enhancements in Java 9 Streams
Enhancements in Java 9 StreamsEnhancements in Java 9 Streams
Enhancements in Java 9 Streams
 
Empathic API-Design
Empathic API-DesignEmpathic API-Design
Empathic API-Design
 
Performance Comparison JVM Languages
Performance Comparison JVM LanguagesPerformance Comparison JVM Languages
Performance Comparison JVM Languages
 
Microservices Patterns and Anti-Patterns
Microservices Patterns and Anti-PatternsMicroservices Patterns and Anti-Patterns
Microservices Patterns and Anti-Patterns
 
Consume Spring Data Rest with Angularjs
Consume Spring Data Rest with AngularjsConsume Spring Data Rest with Angularjs
Consume Spring Data Rest with Angularjs
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring Data
 
Data repositories
Data repositoriesData repositories
Data repositories
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 

Recently uploaded

First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 

Recently uploaded (20)

First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 

Reactive Spring 5

  • 1. Reactive Spring 5 Reactive Programming with Spring WebFlux and Spring Data Corneil du Plessis
  • 2. About Me • Working as Programmer since 1985 • Smallest to very large systems. • Cobol, Fortan, Pascal, Algol, C/C++, Java, JavaScript, Groovy, Python, Scala, Kotlin and more. • Scientific instrumentation, Sports event management, Mining, Banking, Treasury and Insurance. • Software Architect (with a preference for coding)
  • 3. A definition reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change Wikipedia
  • 4. Reactive Manifesto • Responsive • Resilient • Elastic • Message Driven
  • 5. Why reactive programming? • Handle back-pressure • Communicate change • Scalability • Performance • Reliability
  • 6. Reactive Programming Models • Windows API • JVM Based • NIO • LMAX Disruptor • Akka Actor Model • JavaScript • AJAX • Promises • jQuery • Angular • React • FRP – Functional Reactive Programming • map, reduce, filter • Languages not limited to: • Scala • Kotlin • Haskell • Elm • Groovy • JavaScript • Java 8
  • 7. Road to Reactive Spring • RxJava – 2011-2012 by Netflix • Project Reactor – 2013 by Pivotal • Reactive Streams Specification – 2014 collaboration by Netflix, Pivotal, Red Hat, Twitter, Typesafe and more. • reactor-spring • Spring 5
  • 8. Implementing Technologies HttpHander / WebHander API • Netty • Undertow • Tomcat with Servlet 3.1 • Jetty with Servlet 3.1 Reactive Databases • MongoDB Reactive Streams Driver • Reactive Cassandra (RxJava) • Lettuce (Reactive Streams for Redis) • Reactive Couchbase.
  • 9. Reactive Streams specification • Publisher • Subscriber • Subscription • Processor
  • 10. Reactive Streams – Sequence Diagrams Subscribe Publish
  • 11. Project Reactor • Implements Reactive Streams specification • Influenced by RxJava • Influenced by Java 8 Streams • Improved Developer Experience • Mono<T> - 0 or One • Flux<T> - 0 or More
  • 12. Project Reactor - Mono static <T> Mono<T> just(T data); static <T> Mono<T> fromFuture( CompleteableFuture<? extends T>); Mono<T> log(String category); T block(); T block(Duration timeout); map, flatMap, filter
  • 13. Project Reactor - Flux static <T> Flux<T> just(T data); static <T> Flux<T> just(T … data); static <T> Flux<T> fromStream(Stream<T> s); static <T> Flux<T> fromIterable<Iterable<T> i); Flux<T> log(String category); static <T> Mono<List<T>> collectList(); Mono<T> next(); Iterable<T> toIterable(); Stream<T> toStream(); map, flatMap, filter, reduce
  • 14. Reactive Spring WebFlux • Annotated Controllers • @Controller or @RestController • @RequestMapping / @GetMapping / @PostMapping etc. • Flux instead of Collection • Functional Endpoints • Router Function • Handler Function • HandlerFilter Function
  • 15. Spring MVC @RestController public class HistoryController { private HistoryInterface locHist; public HistoryController(HistoryInterface locHist) { this. locHist = locHist; } @GetMapping(path = "/last30days") public Collection<LocationHistory> find( @RequestParam("startDate") Date startDate, @RequestParam("endDate") Date endDate) { return locHist.find(startDate, endDate); } }
  • 16. Reactive Spring WebFlux @RestController public class HistoryController { private HistoryInterface locHist; public HistoryController(HistoryInterface locHist) { this. locHist = locHist; } @GetMapping(path = "/last30days") public Flux<LocationHistory> find( @RequestParam("startDate") Date startDate, @RequestParam("endDate") Date endDate) { return locHist.find(startDate, endDate); } }
  • 17. Reactive Spring WebFlux (Functional Endpoint) public class HistoryHandler { private HistoryInterface locHist; public History HistoryHandler( HistoryInterface locHist) { this. locHist = locHist; } public Mono<ServerResponse> find(ServerRequest request) { Date startDate = DateUtils.from(request.queryParam("startDate")); Date endDate = DateUtils.from(request.queryParam("endDate")); return ServerResponse.ok() .contentType(APPLICATION_JSON) .body(locHist.find(startDate, endDate), LocationHistory.class); } }
  • 18. Reactive Spring WebFlux (Functional Endpoint) @Configuration @EnableWebFlux public class HistoryConfiguration { @Autowire private HistoryHandler histHandler; @Bean RouterFunction<ServerResponse> router() { return route(GET("/last30days") .and(accept(APPLICATION_JSON)), histHandler::find); } }
  • 19. Spring Data public interface LocationHistoryRepository extends CrudRepository<LocationHistory, String> { Collection<LocationHistory> findByTimestampBetween( Date s, Date e); }
  • 20. Reactive Spring Data public interface LocationHistoryRepository extends ReactiveCrudRepository<LocationHistory, String> { Flux<LocationHistory> findByTimestampBetween( Date s, Date e); }
  • 21. Spring Data JPA • Spring Data JPA does not have Reactive Support. • Streams will provide best experience until reactive JDBC and JPA is available. // Repository method Stream<LocationHistory> findByDateBetween( Date startDate, Date endDate); // Service method return Flux.fromStream(repository.findByDateBetween(s,e));
  • 22. Demo Non-reactive • Spring Boot 1.5.8 • Spring MVC • Spring Data MongoDB Reactive • Spring Boot 2.0 RC • Spring WebFlux • Spring Data Reactive MongoDB
  • 23. Call timing Non-reactive • 0.000 >> controller • 0.000 >> service • 0.409 << service • 0.409 << controller Reactive • 0.000 >> controller • 0.000 >> service • 0.001 << service • 0.001 << controller
  • 26. Network timing Non-reactive Type Time Name lookup 0.004 Connect 0.005 Pre transfer 0.005 Start Transfer 0.419 Total 0.532 Reactive Type Time Name lookup 0.004 Connect 0.005 Pre transfer 0.005 Start Transfer 0.385 Total 0.425
  • 27. More aspects of Reactive Programming • Error handling • Back pressure • Retry • Timeouts • Transactions
  • 28. Thoughts on Reactive Spring • Pros • Great documentation • Preserves program structure • Safer concurrency • Simpler abstraction than RxJava without sacrificing the power. • Facilitates good practice • Kotlin support in Core • Cons • Debugging complexity • Could not find any other negative comments
  • 29. See Also • ReactiveX • Languages • RxJava • RxKotlin • RxGroovy • RxClojure • RxSwift • Rx.Net (C#) and more… • Platforms • RxAndroid • RxCocoa • RxNetty • Akka & Akka Streams • Ratpack • Vert.x • Play Framework • Languages • Reactor Scala Extensions • Reactor Kotlin Extensions (now in core) • Messaging Communication • Reactor Kafka • Reactor RabbitMQ • Reactor Aeron • Reactor Netty
  • 30. Finally • Source - https://github.com/corneil/reactive-spring-5 • Slides - https://www.slideshare.net/CorneilduPlessis/reactive- spring-5 • Resources • Project Reactor Site - https://projectreactor.io/ • David Karnok's Blog - http://akarnokd.blogspot.co.za/ Questions?