SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Reactive for the
Impatient
(Java Edition)
Mary Grygleski
Java Developer Advocate
@mgrygles
DOC ID / Month XX, 2018 / © 2018 IBM Corporation
A Gentle Intro to Reactive Programming and Reactive Systems with a
survey of
4 popular Reactive Java tools and libraries:
RxJava
Spring Reactor
Akka
Eclipse Vert.x
2
Why
Reactive?
3
Evolving changes/demands in the Computing Ecosystem
4
• Hardware level
• * Virtualization and cloud strategies
• Software System Level
• Software Application Level
• The impatient human beings!
What is
Reactive?
5
6
Reactive Manifesto
https://www.reactivemanifesto.org
Version 2.0 (September 2014)
* More flexible systems
*Highly responsive
*More tolerant of failures
*Handling of failures
DOC ID / Month XX, 2018 / © 2018 IBM Corporation
7
Reactive Principles
DOC ID / Month XX, 2018 / © 2018 IBM Corporation
Important distinctions…
8
Functional Reactive
Programming
Reactive
Programming
Reactive Systems and
Architecture
Event-Driven vs Message-Driven
9
An Interesting
”Reactive”
Use Case:
Menya Musashi
Ramen Shop in
Tokyo
10
Reactive Programming: Patterns, Terminologies
11
• Reactivity
• Events
• Streams
• Observables
Design Patterns:
Observer, Composite, Iterator
Rx Marble Diagram
12
Rx Marble Diagram: Map()
13
Observable.just(1, 2, 3)
.map(x -> 10 * x)
.subscribe(x -> Timber.d("item: " + x)));
Output:
item: 10
item: 20
item: 30
Source: https://rxmarbles.com
Reactive Systems Design: Patterns
14
• State Management and Persistence Patterns
• Flow Control Patterns
• Message Flow Patterns
• Fault Tolerance and Recovery Patterns
• Replication Patterns
• Resource Management Patterns
Reactive Systems Design: Terminologies
15
• Reactive Microservices vs Monoliths
• Isolation of State, Space, Time, Failure
• Circuit Breakers
• Back –Pressure
• High Availability
• Eventual Consistency
• *CAP Theorem
Reactive Streams
16
• Specifications 1.0
• Working groups started in 2013: Netflix, Pivotal, LightBend – later joined by
Oracle, Twitter, Red Hat, spray.io
• Standard for asynchronous stream processing with non-blocking back pressure
• Initial release: May 2015
• Latest release: August 2017
What about Microservices?
17
How are Microservices related to Reactive Programming, and
also Reactive Systems?
Lagom – A Reactive Microservices Framework
18
• From LightBend
• Built on the Play Framework and Akka Cluster
• RPC-style programming style
• Message Broker API implemented in Akka Streams and Kafka
• Persistence based on the concept of Entities – Domain-Driven Design
• Event-sourcing
• CQRS
19
20
"Reactive” Design Thinking
21
RxJava
* Java implementation of ReactiveX (reactivex.io)
* Very popular, especially on Android.
* Also available in Javascript, .NET, Scala, Clojure, Swift (and more!) with equivalent api.
* v1 (pre reactive streams specification) 2014
* v2 2016 (Flowable, with backpressure)
22
Simple example: Hello World
public static void hello(String... args) {
Flowable.fromArray(args).subscribe(s -> System.out.println("Hello " + s + "!"));
}
23
package com.ibm.reactive.samples;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
public class RxJava2Example
{
public static void main(String[] args)
{
//producer
Observable<String> observable = Observable.just("how", "to", "do", "in", "java");
//consumer
Consumer<? super String> consumer = System.out::println;
//Attaching producer to consumer
observable.subscribe(consumer);
}
}
24
Spring Reactor
* Based on Project Reactor from Pivotal
* Very similar api to RxJava2
* Built for Java 8+ allowing for cleaner interface.
* David Karnok (project lead of RxJava, engine contributor to Reactor)
David Karnok@akarnokd
Use Reactor 3 if you are allowed to use Java 8+, use RxJava 2 if you are stuck on Java 6+ or need your functions
to throw checked exceptions
(Twitter: Sep 10th, 2016)
* Reactor Core
* Reactor Test
* Reactor Extra
* Reactor Netty
* Reactor Adapter
* Reactor Kafka
* Reactor RabbitMQ
* Incubating reactive streams foundation for .Net, Javascript
25
Spring 5: Spring Web Reactive (non-blocking web stack)
Traditional Approach (Spring MVC):
@GetMapping("/traditional")
public List < Product > getAllProducts() {
System.out.println("Traditional way started");
List < Product > products = prodService.getProducts("traditional");
System.out.println("Traditional way completed");
return products;
}
Reactive Approach (Spring Web Reactive – Web Flux):
@GetMapping(value = "/reactive", .TEXT_EVENT_STREAM_VALUE)
public Flux < Product > getAll() {
System.out.println("Reactive way using Flux started");
Flux < Product > fluxProducts = prodService.getProductsStream("Flux");
System.out.println("Reactive way using Flux completed");
return fluxProducts;
}
26
Quick comparison: RxJava vs Spring Reactor
27
Akka
* From LightBend. - IBM Partnership (June 2017)
https://www.lightbend.com/ibm-alliance
* Actor Model (from Erlang – Actor Programming Model in the 1980’s)
* Event-Driven
* Location Transparency
* Lightweight
* Resiliency/Recoverability – Supervisor capability
28
package sample.hello;
public class Main {
public static void main(String[] args) {
akka.Main.main(new String[] { HelloWorld.class.getName() });
}
}
29
package sample.hello;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
import static sample.hello.Greeter.Msg;
public class HelloWorld extends AbstractActor {
@Override
public Receive createReceive() {
return receiveBuilder()
.matchEquals(Msg.DONE, m -> {
// when the greeter is done, stop this actor and with it the application
getContext().stop(self());
})
.build();
}
@Override
public void preStart() {
// create the greeter actor
final ActorRef greeter = getContext().actorOf(Props.create(Greeter.class), "greeter");
// tell it to perform the greeting
greeter.tell(Msg.GREET, self());
}
}
30
package sample.hello;
import akka.actor.AbstractActor;
public class Greeter extends AbstractActor {
public static enum Msg {
GREET, DONE;
}
@Override
public Receive createReceive() {
return receiveBuilder()
.matchEquals(Msg.GREET, m -> {
System.out.println("Hello World!");
sender().tell(Msg.DONE, self());
})
.build();
}
}
31
import akka.actor.{Actor, ActorSystem, Props}
//greet message
case class Greet(name: String)
//greeter Actor
class Greeter extends Actor {
def receive = {
case Greet(name) => println(s"Hello $name")
}
}
object HelloAkka extends App {
val system=ActorSystem("Intro-Akka")
val greeter=system.actorOf(Props[Greeter],"greeter")
greeter ! Greet("Akka")
}
32
Vert.x
* From Eclipse
* A very flexible “polyglot” framework that interoperates with other frameworks and tools.
-> RxJava
-> Spring Reactor
-> Akka
-> not to mention the other non-Java frameworks and tools as well (JS, .Net…)
* Verticles – components that are being deployed and executed by Vert.x
-> event-driven
-> run only when they receive a message
* Vert.x event bus
* Not restrictively tied to any container – Vert.x libraries can be used with other libraries
33
package io.vertx.example;
import io.vertx.core.Vertx;
public class HelloWorldEmbedded {
public static void main(String[] args) {
// Create an HTTP server which simply returns "Hello World!" to each request.
Vertx.vertx().createHttpServer().requestHandler(req -> req.response().end("Hello
World!")).listen(8080);
}
Recap & Takeaways
* Reactive is an overloaded word in today’s market
* Not for the ”faint of heart” but for the determined
* Reactive programming is not the same as Functional
Reactive programming or Reactive systems
* Benefits of being “Reactive” on the programming level
* Reactive systems and architecture bring “reactivity” to
another level
* Reactivity to this day has not been fully ready on the
database level, despite some significant efforts on the
database connectivity level
34
35
Thank you
twitter.com/mgrygles
github.com/mgrygles
developer.ibm.com/profiles/mary.grygleski
IBM Cloud:
https://ibm.biz/BdzRUQ
https://developer.ibm.com/technologies/reactive-systems/
https://www.lightbend.com/ibm-alliance
https://www.reactivemanifesto.org
https://www.reactivedesignpatterns.com
36
IBM’s Multi-Year Initiative for a Good Cause
http://callforcode.org
IBM’s Multi-Year Initiative for a Good Cause
http://callforcode.org
37

Weitere ähnliche Inhalte

Was ist angesagt?

A Tour of the Modern Java Platform
A Tour of the Modern Java PlatformA Tour of the Modern Java Platform
A Tour of the Modern Java PlatformVMware Tanzu
 
Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupAccenture Hungary
 
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Codemotion
 
Let’s go reactive with JAVA
Let’s go reactive with JAVALet’s go reactive with JAVA
Let’s go reactive with JAVATech Triveni
 
Reactive Microservice And Spring5
Reactive Microservice And Spring5Reactive Microservice And Spring5
Reactive Microservice And Spring5Jay Lee
 
JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database Yolande Poirier
 
Architecture of Falcon, a new chat messaging backend system build on Scala
Architecture of Falcon,  a new chat messaging backend system  build on ScalaArchitecture of Falcon,  a new chat messaging backend system  build on Scala
Architecture of Falcon, a new chat messaging backend system build on ScalaTanUkkii
 
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
AAI 2235-OpenJPA and EclipseLink Usage Scenarios ExplainedAAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
AAI 2235-OpenJPA and EclipseLink Usage Scenarios ExplainedKevin Sutter
 
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)Kevin Sutter
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDan Stine
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entityToni Jara
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using GoCloudOps2005
 
Spring Boot and Microservices
Spring Boot and MicroservicesSpring Boot and Microservices
Spring Boot and Microservicesseges
 

Was ist angesagt? (20)

A Tour of the Modern Java Platform
A Tour of the Modern Java PlatformA Tour of the Modern Java Platform
A Tour of the Modern Java Platform
 
Docker+java
Docker+javaDocker+java
Docker+java
 
Reactors.io
Reactors.ioReactors.io
Reactors.io
 
Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology Meetup
 
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
Javantura v4 - (Spring)Boot your application on Red Hat middleware stack - Al...
 
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
 
Reactive Spring 5
Reactive Spring 5Reactive Spring 5
Reactive Spring 5
 
Let’s go reactive with JAVA
Let’s go reactive with JAVALet’s go reactive with JAVA
Let’s go reactive with JAVA
 
Reactive Microservice And Spring5
Reactive Microservice And Spring5Reactive Microservice And Spring5
Reactive Microservice And Spring5
 
JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database
 
EclipseLink JPA
EclipseLink JPAEclipseLink JPA
EclipseLink JPA
 
Architecture of Falcon, a new chat messaging backend system build on Scala
Architecture of Falcon,  a new chat messaging backend system  build on ScalaArchitecture of Falcon,  a new chat messaging backend system  build on Scala
Architecture of Falcon, a new chat messaging backend system build on Scala
 
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
AAI 2235-OpenJPA and EclipseLink Usage Scenarios ExplainedAAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
 
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and Liquibase
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
Spring Boot and Microservices
Spring Boot and MicroservicesSpring Boot and Microservices
Spring Boot and Microservices
 
Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
 

Ähnlich wie Reactive for the Impatient - Mary Grygleski

Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018Matt Raible
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCKonrad Malawski
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusEmily Jiang
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016Trayan Iliev
 
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Loiane Groner
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"LogeekNightUkraine
 
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 ReactorVMware Tanzu
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Loiane Groner
 
Cloud nativeworkshop
Cloud nativeworkshopCloud nativeworkshop
Cloud nativeworkshopEmily Jiang
 
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Matt Raible
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupRoy Russo
 
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Matt Raible
 
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
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3Zachary Klein
 
Reactive Functional Programming with Java 8 on Android N
Reactive Functional Programming with Java 8 on Android NReactive Functional Programming with Java 8 on Android N
Reactive Functional Programming with Java 8 on Android NShipeng Xu
 
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Open stack ocata summit  enabling aws lambda-like functionality with openstac...Open stack ocata summit  enabling aws lambda-like functionality with openstac...
Open stack ocata summit enabling aws lambda-like functionality with openstac...Shaun Murakami
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfRed Hat
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 

Ähnlich wie Reactive for the Impatient - Mary Grygleski (20)

Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016
 
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"
 
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
 
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
 
Cloud nativeworkshop
Cloud nativeworkshopCloud nativeworkshop
Cloud nativeworkshop
 
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
 
Vert.x devoxx london 2013
Vert.x devoxx london 2013Vert.x devoxx london 2013
Vert.x devoxx london 2013
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users Group
 
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
 
Reactive Functional Programming with Java 8 on Android N
Reactive Functional Programming with Java 8 on Android NReactive Functional Programming with Java 8 on Android N
Reactive Functional Programming with Java 8 on Android N
 
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Open stack ocata summit  enabling aws lambda-like functionality with openstac...Open stack ocata summit  enabling aws lambda-like functionality with openstac...
Open stack ocata summit enabling aws lambda-like functionality with openstac...
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 

Kürzlich hochgeladen

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 

Kürzlich hochgeladen (20)

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 

Reactive for the Impatient - Mary Grygleski

  • 1. Reactive for the Impatient (Java Edition) Mary Grygleski Java Developer Advocate @mgrygles DOC ID / Month XX, 2018 / © 2018 IBM Corporation
  • 2. A Gentle Intro to Reactive Programming and Reactive Systems with a survey of 4 popular Reactive Java tools and libraries: RxJava Spring Reactor Akka Eclipse Vert.x 2
  • 4. Evolving changes/demands in the Computing Ecosystem 4 • Hardware level • * Virtualization and cloud strategies • Software System Level • Software Application Level • The impatient human beings!
  • 6. 6 Reactive Manifesto https://www.reactivemanifesto.org Version 2.0 (September 2014) * More flexible systems *Highly responsive *More tolerant of failures *Handling of failures DOC ID / Month XX, 2018 / © 2018 IBM Corporation
  • 7. 7 Reactive Principles DOC ID / Month XX, 2018 / © 2018 IBM Corporation
  • 10. An Interesting ”Reactive” Use Case: Menya Musashi Ramen Shop in Tokyo 10
  • 11. Reactive Programming: Patterns, Terminologies 11 • Reactivity • Events • Streams • Observables Design Patterns: Observer, Composite, Iterator
  • 13. Rx Marble Diagram: Map() 13 Observable.just(1, 2, 3) .map(x -> 10 * x) .subscribe(x -> Timber.d("item: " + x))); Output: item: 10 item: 20 item: 30 Source: https://rxmarbles.com
  • 14. Reactive Systems Design: Patterns 14 • State Management and Persistence Patterns • Flow Control Patterns • Message Flow Patterns • Fault Tolerance and Recovery Patterns • Replication Patterns • Resource Management Patterns
  • 15. Reactive Systems Design: Terminologies 15 • Reactive Microservices vs Monoliths • Isolation of State, Space, Time, Failure • Circuit Breakers • Back –Pressure • High Availability • Eventual Consistency • *CAP Theorem
  • 16. Reactive Streams 16 • Specifications 1.0 • Working groups started in 2013: Netflix, Pivotal, LightBend – later joined by Oracle, Twitter, Red Hat, spray.io • Standard for asynchronous stream processing with non-blocking back pressure • Initial release: May 2015 • Latest release: August 2017
  • 17. What about Microservices? 17 How are Microservices related to Reactive Programming, and also Reactive Systems?
  • 18. Lagom – A Reactive Microservices Framework 18 • From LightBend • Built on the Play Framework and Akka Cluster • RPC-style programming style • Message Broker API implemented in Akka Streams and Kafka • Persistence based on the concept of Entities – Domain-Driven Design • Event-sourcing • CQRS
  • 19. 19
  • 21. 21 RxJava * Java implementation of ReactiveX (reactivex.io) * Very popular, especially on Android. * Also available in Javascript, .NET, Scala, Clojure, Swift (and more!) with equivalent api. * v1 (pre reactive streams specification) 2014 * v2 2016 (Flowable, with backpressure)
  • 22. 22 Simple example: Hello World public static void hello(String... args) { Flowable.fromArray(args).subscribe(s -> System.out.println("Hello " + s + "!")); }
  • 23. 23 package com.ibm.reactive.samples; import io.reactivex.Observable; import io.reactivex.functions.Consumer; public class RxJava2Example { public static void main(String[] args) { //producer Observable<String> observable = Observable.just("how", "to", "do", "in", "java"); //consumer Consumer<? super String> consumer = System.out::println; //Attaching producer to consumer observable.subscribe(consumer); } }
  • 24. 24 Spring Reactor * Based on Project Reactor from Pivotal * Very similar api to RxJava2 * Built for Java 8+ allowing for cleaner interface. * David Karnok (project lead of RxJava, engine contributor to Reactor) David Karnok@akarnokd Use Reactor 3 if you are allowed to use Java 8+, use RxJava 2 if you are stuck on Java 6+ or need your functions to throw checked exceptions (Twitter: Sep 10th, 2016) * Reactor Core * Reactor Test * Reactor Extra * Reactor Netty * Reactor Adapter * Reactor Kafka * Reactor RabbitMQ * Incubating reactive streams foundation for .Net, Javascript
  • 25. 25 Spring 5: Spring Web Reactive (non-blocking web stack) Traditional Approach (Spring MVC): @GetMapping("/traditional") public List < Product > getAllProducts() { System.out.println("Traditional way started"); List < Product > products = prodService.getProducts("traditional"); System.out.println("Traditional way completed"); return products; } Reactive Approach (Spring Web Reactive – Web Flux): @GetMapping(value = "/reactive", .TEXT_EVENT_STREAM_VALUE) public Flux < Product > getAll() { System.out.println("Reactive way using Flux started"); Flux < Product > fluxProducts = prodService.getProductsStream("Flux"); System.out.println("Reactive way using Flux completed"); return fluxProducts; }
  • 26. 26 Quick comparison: RxJava vs Spring Reactor
  • 27. 27 Akka * From LightBend. - IBM Partnership (June 2017) https://www.lightbend.com/ibm-alliance * Actor Model (from Erlang – Actor Programming Model in the 1980’s) * Event-Driven * Location Transparency * Lightweight * Resiliency/Recoverability – Supervisor capability
  • 28. 28 package sample.hello; public class Main { public static void main(String[] args) { akka.Main.main(new String[] { HelloWorld.class.getName() }); } }
  • 29. 29 package sample.hello; import akka.actor.AbstractActor; import akka.actor.ActorRef; import akka.actor.Props; import static sample.hello.Greeter.Msg; public class HelloWorld extends AbstractActor { @Override public Receive createReceive() { return receiveBuilder() .matchEquals(Msg.DONE, m -> { // when the greeter is done, stop this actor and with it the application getContext().stop(self()); }) .build(); } @Override public void preStart() { // create the greeter actor final ActorRef greeter = getContext().actorOf(Props.create(Greeter.class), "greeter"); // tell it to perform the greeting greeter.tell(Msg.GREET, self()); } }
  • 30. 30 package sample.hello; import akka.actor.AbstractActor; public class Greeter extends AbstractActor { public static enum Msg { GREET, DONE; } @Override public Receive createReceive() { return receiveBuilder() .matchEquals(Msg.GREET, m -> { System.out.println("Hello World!"); sender().tell(Msg.DONE, self()); }) .build(); } }
  • 31. 31 import akka.actor.{Actor, ActorSystem, Props} //greet message case class Greet(name: String) //greeter Actor class Greeter extends Actor { def receive = { case Greet(name) => println(s"Hello $name") } } object HelloAkka extends App { val system=ActorSystem("Intro-Akka") val greeter=system.actorOf(Props[Greeter],"greeter") greeter ! Greet("Akka") }
  • 32. 32 Vert.x * From Eclipse * A very flexible “polyglot” framework that interoperates with other frameworks and tools. -> RxJava -> Spring Reactor -> Akka -> not to mention the other non-Java frameworks and tools as well (JS, .Net…) * Verticles – components that are being deployed and executed by Vert.x -> event-driven -> run only when they receive a message * Vert.x event bus * Not restrictively tied to any container – Vert.x libraries can be used with other libraries
  • 33. 33 package io.vertx.example; import io.vertx.core.Vertx; public class HelloWorldEmbedded { public static void main(String[] args) { // Create an HTTP server which simply returns "Hello World!" to each request. Vertx.vertx().createHttpServer().requestHandler(req -> req.response().end("Hello World!")).listen(8080); }
  • 34. Recap & Takeaways * Reactive is an overloaded word in today’s market * Not for the ”faint of heart” but for the determined * Reactive programming is not the same as Functional Reactive programming or Reactive systems * Benefits of being “Reactive” on the programming level * Reactive systems and architecture bring “reactivity” to another level * Reactivity to this day has not been fully ready on the database level, despite some significant efforts on the database connectivity level 34
  • 36. 36 IBM’s Multi-Year Initiative for a Good Cause http://callforcode.org IBM’s Multi-Year Initiative for a Good Cause http://callforcode.org
  • 37. 37