SlideShare a Scribd company logo
1 of 88
Download to read offline
© Copyright 2017 Pivotal Software, Inc. All rights Reserved. Version 1.0
Applications Réactives
dans le Cloud
Simon Baslé
Agenda
● Programmation Réactive
● Reactor
○ Flux / Mono
○ Operateurs
● Intégration dans le Cloud
○ Composition
○ Erreurs
○ Latence
● Intégration dans Spring
○ Spring WebFlux
○ Spring Data
○ Spring Boot
Programmation Réactive?
Composer des séquences d’
évènements asynchrones
Paradigme
Séquences
d´évènements
Composer des séquences d’évènements
asynchrones
Asynchrones
Composer des séquences d’évènements
asynchrones
Composer
Composer des séquences d’évènements
asynchrones
Reactive Streams
Reactive Streams
(un peu d’histoire)
Reactive Streams
les interfaces
Publisher<T>
&
Subscriber<T>
Publisher<Music>
Subscriber<Music>
Publisher<T>
void subscribe(Subscriber<T>)
Subscriber<T>
void onNext(T)
void onComplete()
void onError(Throwable)
mais
ca n’est pas tout !
Publisher<T>
Subscription<T>
Subscriber<T>
Subscription<Music>
Subscriber<T>
void onNext(T)
void onComplete()
void onError(Throwable)
void onSubscribe(Subscription<T>)
Subscription<T>
void request(long)
void cancel()
C’est la
Backpressure
Processor<T, R>
= Subscriber<T> + Publisher<R>
Processor<Music, Music>
Subscriber
Publisher
Reactor
2 types de Publisher
Flux et Mono
Flux
0-N éléments
Publisher “classique”
Mono
0-1 éléments
Publisher “spécialisé”
Applications Réactives dans le Cloud
Applications Réactives dans le Cloud
“diagrammes à bille”
ou Marble Diagrams
Flux d’entrée
éléments
opérateur
générant le
flux de
sortie
Flux de sortie
complétion onComplete
complétion onError
API riche
API riche
API riche
API riche
API riche
API riche
API riche
Intégration dans le Cloud?
de services asynchrones
ou de Microservices
distants, avec des
besoins de composition
avancés.
Favorise la
composition
Stop au Callback Hell
Composition avancée
Combiner des sources multiples
Callback Hell?
Bienvenue dans l’Enfer des Callbacks
firstService.call(new Callback<String> {
public void success(String str) {
secondService. call(str, new Callback<Integer>() {
public void success(Integer valueA) {
thirdService. call(str, new Callback<Integer>() {
public void success(Integer valueB) {
displayTwoValues(str, valueA + valueB);
}
public void error(Throwable error) {
displayAlert(error);
}};
}
public void error(Throwable error) {
displayAlert(error);
}};
}
public void error(Throwable error) {
displayAlert(error);
}
}
Adieu Callback Hell
firstService.callMono()
.flatMap( str -> Mono.just(str)
.zipWith(secondService. callMono(str)
.zipWith(thirdService. callMono(str),
Integer::sum)
)
)
.subscribe(
pair -> displayTwoValues(pair.getT1(), pair.getT2()),
this::displayAlert);
Applications
multiples
Combiner des sources
multiples
1ère Application
zip(
database.queryMono(),
inMemory.skip(3)
.take(1),
httpClient.get(id)
)
Aller chercher plus de données
2ème Application
db.allUsers()
.flatMap(u -> avatarService
.avatarFor(u.getEmail())
)
Favoriser la source
la plus rapide
3ème Application
Mono.first(
db.allUsers(),
cache.get(“all_users”)
)
Observer des données
sur une fenêtre glissante
4ème Application
connectedUsers
.window(Duration
.ofSeconds(30))
.flatMap(Flux::count)
.subscribe(dashboard::update)
Gestion des
Erreurs
Intégrée à l’API
Les erreurs sont définitives
Reprise, Retry
Prévenir les erreurs en cascade
Les erreurs sont
définitives
et
pourtant...
Reprise sur erreurs
...il existe des opérateurs de
onErrorReturn(T)
onErrorResume(
Publisher<T>)
onErrorResume(
Publisher<T>)
Le Flux original s’est
bel et bien TERMINÉ
Il s’agit d’un NOUVEAU Flux
Retry
Encore plus visible avec
Route fermée?
Retry!
Peut retomber
en erreur...
… or finalement
réussir
Re-souscription
Retry fonctionne par
Prévenir les
erreurs en cascade
Timeout
db.allUsers()
.flatMap(u -> avatarService
.avatarFor(u.getEmail())
)
db.allUsers()
.flatMap(u -> avatarService
.avatarFor(u.getEmail())
.timeout(Duration.ofMillis(500))
.onErrorReturn(defaultAvatar)
)
Intégration
dans Spring
Spring 5, Spring Boot 2
Spring WebFlux
@GetMapping(“/users/{name}”)
Flux<User> getByName(@PathVariable
String name) {
…
}
Spring Data
public interface UserRepository
extends ReactiveCrudRepository<User,String>
{
Flux<User> findByLastname(String lastname);
}
@GetMapping(“/users/{name}”)
Flux<User> getName(@PathVariable name) {
return userRepo
.findByLastName(name);
}
Spring Boot 2
Intégration de Reactor,
Actuators réactifs, Spring
Security, ...
Spring Boot 2 - M7 fin Novembre
Et dans la vraie vie?
Construire un
profil utilisateur
en joignant des appels à
GitHub
Gravatar
StackOverflow
The end
Thank You!
Questions?
Credits
● https://19f4g9425ypu3nc2jy13bbrh-wpengine.netdna-ssl.com/wp-content/uploads/2016/12/Are-Roundabouts-Safer.jpg
● https://c1.staticflickr.com/8/7181/6845075775_f31a51f2e2_b.jpg
● https://cdn.pixabay.com/photo/2017/06/11/11/09/the-road-to-the-sea-2392024_1280.jpg
● https://cdn.pixabay.com/photo/2016/03/09/10/37/light-bulb-1246043_1280.jpg
● https://c.pxhere.com/photos/93/8e/child_statue_bronze_outside_outdoors_summer_children_shock-1334495.jpg!d
● https://c1.staticflickr.com/4/3266/2309047966_1860f7e723_b.jpg
● https://static.pexels.com/photos/164693/pexels-photo-164693.jpeg
● https://pxhere.com/en/photo/888366
● https://c.pxhere.com/photos/67/38/headphone_earphone_technology_audio-1389022.jpg!d
● https://static.pexels.com/photos/164829/pexels-photo-164829.jpeg

More Related Content

More from VMware Tanzu

Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023VMware Tanzu
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptxVMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchVMware Tanzu
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishVMware Tanzu
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVMware Tanzu
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - FrenchVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootVMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerVMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeVMware Tanzu
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsVMware Tanzu
 
SpringOne Tour: Doing Progressive Delivery with your Team
SpringOne Tour: Doing Progressive Delivery with your TeamSpringOne Tour: Doing Progressive Delivery with your Team
SpringOne Tour: Doing Progressive Delivery with your TeamVMware Tanzu
 
SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...
SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...
SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...VMware Tanzu
 
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps EnterpriseSpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps EnterpriseVMware Tanzu
 
SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...
SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...
SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...VMware Tanzu
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondVMware Tanzu
 
SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...
SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...
SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...VMware Tanzu
 
Tanzu Developer Connect | Public Sector | March 29, 2023.pdf
Tanzu Developer Connect | Public Sector | March 29, 2023.pdfTanzu Developer Connect | Public Sector | March 29, 2023.pdf
Tanzu Developer Connect | Public Sector | March 29, 2023.pdfVMware Tanzu
 
Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023
Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023
Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023VMware Tanzu
 

More from VMware Tanzu (20)

Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 
SpringOne Tour: Doing Progressive Delivery with your Team
SpringOne Tour: Doing Progressive Delivery with your TeamSpringOne Tour: Doing Progressive Delivery with your Team
SpringOne Tour: Doing Progressive Delivery with your Team
 
SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...
SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...
SpringOne Tour: Make the Right Thing the Obvious Thing: The Journey to Intern...
 
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps EnterpriseSpringOne Tour: An Introduction to Azure Spring Apps Enterprise
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
 
SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...
SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...
SpringOne Tour: 10 Practical Tips for Building Native and Serverless Spring A...
 
SpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and BeyondSpringOne Tour: Spring Boot 3 and Beyond
SpringOne Tour: Spring Boot 3 and Beyond
 
SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...
SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...
SpringOne Tour 2023: Let's Get Streaming! A Guide to Orchestrating Spring Clo...
 
Tanzu Developer Connect | Public Sector | March 29, 2023.pdf
Tanzu Developer Connect | Public Sector | March 29, 2023.pdfTanzu Developer Connect | Public Sector | March 29, 2023.pdf
Tanzu Developer Connect | Public Sector | March 29, 2023.pdf
 
Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023
Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023
Simplify and Scale Enterprise Spring Apps in the Cloud | March 23, 2023
 

Applications Réactives dans le Cloud