SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
Vert.X
high performance polyglot application toolkit
Xavier MARIN
@XavMarin
https://github.com/Giwi
Architecte chez @cmarkea
CTO chez @qaobee
Petite histoire
● Créé par Tim Fox @timfox
● en 2011 chez VMWare
● sous le nom de Node.x
● 2012 : devient Vert.X
● 2013 : passe dans la fondation Eclipse
● 24/06/2015 sortie de la v3
● environ 180 contributeurs
https://www.parleys.com/search/vert.x/PRESENTATIONS
Vocabulaire pour
commerciaux
Simple threadSafe concurrent
asynchronous eventDriven
reactive eventBus over a
scalable polyglot embeddable
toolkit plateform
Le problème
● Répondre à un grand
nombre de clients en
même temps
● C10k = 10 000
connexions
simultanées
C10k
C10k
Multi Thread vs Mono Thread + boucle d’événement
Multi Thread vs Mono Thread + boucle d’événement
J2EE Mono Thread + boucle d’événement
Statique EJB JSP Servlet Traitement TPL Statique
x x x x
JBoss
WebSphere
Tomee
Multi Thread vs Mono Thread + boucle d’événement
J2EE Mono Thread + boucle d’événement
Statique EJB JSP Servlet Traitement TPL Statique
x x x x
JBoss
WebSphere
Tomee
x x x Tomcat
Multi Thread vs Mono Thread + boucle d’événement
J2EE Mono Thread + boucle d’événement
Statique EJB JSP Servlet Traitement TPL Statique
x x x x
JBoss
WebSphere
Tomee
x x x Tomcat
x x Jetty
Multi Thread vs Mono Thread + boucle d’événement
J2EE Mono Thread + boucle d’événement
Statique EJB JSP Servlet Traitement TPL Statique
x x x x
JBoss
WebSphere
Tomee
x x x Tomcat
x x Jetty
Serveur HTTP
x
Apache
HTTPD
Multi Thread vs Mono Thread + boucle d’événement
J2EE Mono Thread + boucle d’événement
Statique EJB JSP Servlet Traitement TPL Statique
x x x x
JBoss
WebSphere
Tomee
NodeJS x x x
x x x Tomcat Vert.X x x x
x x Jetty Lagom x x x
Serveur HTTP
x
Apache
HTTPD
NginX x
Système réactif vs programmation réactive
Les applications modernes font face à
de nouveaux défis, bla bla bla
Responsive : répond sur un laps de
temps
Résilient : répond même en cas d’
échec
Elastique : répond quel que soit la
charge
Message-driven : repose sur le la
communication événementielle
asynchrone
http://www.reactivemanifesto.org
Caractéristiques
Réactif
● Responsive
○ Tient la charge (scalable)
○ Robuste (resilience)
● Message-driven
○ événementiel asynchrone
Polyglotte
● Pas que en Java
○ Groovy, Ruby, Javascript
● S’exécute sur la VM
Handler
Event Loop
Handler
Handler
Handler
Handler
Les handlers sont
toujours appelés dans
le même thread
(event loop)
Les handlers ne
bloquent jamais le
thread qui les appelle
message-driven
reactor pattern
Qu’est-ce que ?
● Un message
● Une notification
● Une requête HTTP
● Une commande, une
instruction
● Un fichier
● Un résultat, un rapport, une
erreur
Event Loop
Handler
Handler
Handler
Handler
void operation(param1, param2, Handler< > {
// …
handler.handle( );
// …
}
void handle( ) {
// faire un truc avec
}
Modèle de développement asynchrone
vertx.createHttpServer()
.requestHandler(
req -> req.response().end("Hello there!")
)
.listen(8080,
ar -> {
if (ar.failed()) {
System.out.println("The server failed to start");
} else {
System.out.println("Server started on 8080");
}
}
);
ar : AsyncResult
● status : success ou failed
● result : si success
● cause : si failed
JVM polyglotte
Dois-je coder en java pour exécuter
un programme sur la JVM?
Oui, mais pas que, fais-toi plaisir!
JVM polyglotte
On peut programmer en plus de 200 langages
Java, JavaFX, Ceylon, Gosu, Groovy, Clojure, Rhino Nashorn, Mirah, Scala,
JRuby, Xtend, JPython, Fantom, Oxygene, Kotlin, …
L’intérêt : à chaque problème sa solution
“Quand on n’a qu’un marteau dans la main, les vis
ressemblent à des clous”
Polyglotte
var vertx = require('vertx-js/vertx');
var server = vertx.createHttpServer();
server.requestHandler(function (request) {
var response = request.response();
response.putHeader('content-type', 'text/plain');
response.end('Hello World!');
});
server.listen(8080);
Polyglotte
server = vertx.create_http_server()
server.request_handler() { |request|
response = request.response()
response.put_header("content-type", "text/plain")
response.end("Hello World!")
}
server.listen(8080)
Polyglotte
def server = vertx.createHttpServer()
server.requestHandler({ request ->
def response = request.response()
response.putHeader("content-type", "text/plain")
response.end("Hello World!")
})
server.listen(8080)
Polyglotte
public class Main {
public static void main(String[] args) {
HttpServer server = vertx.createHttpServer();
server.requestHandler(request -> {
HttpServerResponse response = request.response();
response.putHeader("content-type", "text/plain");
response.end("Hello World!");
});
server.listen(8080);
}
}
L’event bus
● Point à point
● Publish / Subscribe
● Requête / réponse
Les messages sont reçus par
des handlers et déposés en
utilisant l’eventLoop
Chaque instance de Vert.X a
accès à l’eventBus
Event Bus
Architecture
Requêtes HTTP
Verticle
Web
Route
Event loop
Bus
WorkerVerticle WorkerVerticle WorkerVerticle
instance
Bus
Architecture
instance instance instance instance
Processeur
Multi-instances
Bus
Architecture
Machine 1 Machine 2 Machine 3
Cluster
L’event bus
L’eventBus permet une
communication distribuée.
Presque tout peut publier un
message sur le bus.
Event Bus
Machine 1
Machine 2
Machine 3
Machine 4
Node
Bin
Event bus
EventBus eb = vertx.eventBus();
MessageConsumer<String> consumer = eb.consumer("news.uk.sport", message -> {
System.out.println("I have received a message: " + message.body());
message.reply("how interesting!");
}).completionHandler(res -> {
if (res.succeeded()) {
System.out.println("Registration has reached all nodes");
} else {
System.out.println("Registration failed!");
}
});
consumer.unregister(res -> {
if (res.succeeded()) {
System.out.println("Un-registration has reached all nodes");
} else {
System.out.println("Un-registration failed!");
}
});
Event bus
Publish / Subscribe
eventBus.publish("news.uk.sport", "You kicked a ball");
Point à point
eventBus.send("news.uk.sport","You kicked a ball",ar ->{
if (ar.succeeded()) {
System.out.println("reply: " + ar.result().body());
}
});
Ajout d'en-tête
DeliveryOptions options = new DeliveryOptions();
options.addHeader("some-header", "some-value");
eventBus.send("news.uk.sport", "You kicked a ball", options);
Verticles : un modèle “agent” ou presque
Les verticles sont des bouts de code
qui sont déployés et exécuté par
Vert.X peu importe le langage.
vertx.deployVerticle("mon.verticle");
Ils ont un cycle de vie : start et stop.
Ils interagissent en utilisant des
événement ou des messages.
Ils peuvent être instanciés plusieurs
fois et se respawn en cas d’échec.
Les workerVerticles traitent le
bloquant
Verticle
Event Bus
Handler
Handler
vertx.deployVerticle("mon.verticle",
new DeploymentOptions().setInstances(3));
Verticles : un modèle “agent” ou presque
Les verticles morts sont redémarés
sur un autre noeud du cluster.
Verticle
Event Bus
Handler
Handler
vertx.deployVerticle("mon.verticle",
new DeploymentOptions().setHA(true));
Machine 1
Machine 2
Machine 3
FailOver
Fail-over demo
Stack Vert.X
http://vertx.io/docs/
core
Web
JDBC Redis
Auth Mongo
JSClient Stomp
Mail JCA
Metrics Rx Sync
Shell docker
SockJS
Bridge
Services
proxies
Stack Vert.X
● Vert.x core
● Vert.x Web
○ Routages et sous-routages
○ Sessions
○ Cookies
○ Sécurité (basic auth, shiro, JWT, …)
○ Templates (Handlebars, Jade, MVEL,
Thymeleaf)
○ SockJS
○ Static files
○ …
● Accès aux données
○ MongoDB, JDBC, Redis, SQL Common
● Intégration
○ Mail et JCA
● Sécurité
○ basic auth, shiro, JWT, JDBC Auth
● Reactive
○ Vert.X Rx, Reactive streams
● Metrics
● Vert.X unit
Accès aux données de manière asynchrone
jdbc.getConnection(ar -> {
SQLConnection connection = ar.result();
connection.query("SELECT * FROM Beer", resp -> {
if (!resp.failed()) {
List<Beer> beverages = resp.result()
.getRows()
.stream()
.map(Beer::new)
.collect(Collectors.toList());
}
//…
});
});
Le Web
HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
Route route = router.route(HttpMethod.PUT, "myapi/orders")
.consumes("application/json")
.produces("application/json");
route.handler(routingContext -> {
// This would be match for any PUT method to paths starting with
// "myapi/orders" with a content-type of "application/json"
// and an accept header matching "application/json"
});
server.requestHandler(router::accept).listen(8080);
HTTP
server
Router
Handler
Handler
réponse HTTP
requête HTTP
Le Web
Router restAPI = Router.router(vertx);
restAPI.get("/products/:productID").handler(rc -> {
// TODO Handle the lookup of the product....
rc.response().write(productJSON);
});
restAPI.put("/products/:productID").handler(rc -> {
// TODO Add a new product…
rc.response().end();
});
Router mainRouter = Router.router(vertx);
// Handle static resources
mainRouter.route("/static/*").handler(StaticHandler.create());
mainRouter.route(".*.templ").handler(myTemplateHandler);
mainRouter.mountSubRouter("/productsAPI", restAPI);
$curl http://localhost:8080/productsAPI/products/1234
Le Web
router.route().path("/*")
.consumes("application/json")
.handler(routingContext -> {
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "application/json");
routingContext.next();
});
router.get("/beers/").handler(routingContext -> {
JsonObject query = new JsonObject();
mongoClient.find("beers", query, res -> {
if (res.succeeded()) {
JsonArray jar = new JsonArray();
res.result().forEach(jar::add);
routingContext.response().end(jar.encodePrettily());
} else {
res.cause().printStackTrace();
}
});
}
Micro services
Les micro-services interagissent en
utilisant l’eventBus ou en utilisant un
autre protocole.
Des service-proxies sont générés
pour l’eventBus.
On peut même consommer les
services depuis NodeJS, le
navigateur, iOS ou Android via
l’eventBus.
Chaque service peut se mettre à l’
échelle en fonction de la charge et
supporte le fail-over.
Service
Event Bus
Service
Service
Packagé dans un
fat-jar
HTTP/REST
AMQP
Service proxy
Source : http://www.cubrid.org
Performances
Source : http://www.cubrid.org
Performances
Source : https://www.techempower.com
Performances
Source : https://www.techempower.com
Performances
Cloud ready
● Vert.x OpenShift Cartridge
○ https://github.com/vert-x3/vertx-openshift-cartridge
● Vert.x OpenShift Using DIY Cartridge
○ https://github.com/vert-x3/vertx-openshift-diy-quickstart
● Vert.x Docker Images
○ https://github.com/vert-x3/vertx-stack/tree/master/stack-docker
Production ready
The end ...
« Si vous avez compris ce que je viens
de vous dire, c’est que je me suis
probablement mal exprimé »
A. Greenspan
https://github.com/Giwi/vertx3-angular-beers

Contenu connexe

Tendances

Elasticsearch 5.0 les nouveautés
Elasticsearch 5.0 les nouveautésElasticsearch 5.0 les nouveautés
Elasticsearch 5.0 les nouveautésMathieu Elie
 
Node.js et les nouvelles technologies javascript
Node.js et les nouvelles technologies javascriptNode.js et les nouvelles technologies javascript
Node.js et les nouvelles technologies javascriptKhalid Jebbari
 
2014.12.11 - TECH CONF #3 - Présentation Node.js
2014.12.11 - TECH CONF #3 - Présentation Node.js2014.12.11 - TECH CONF #3 - Présentation Node.js
2014.12.11 - TECH CONF #3 - Présentation Node.jsTelecomValley
 
Docker en Production (Docker Paris)
Docker en Production (Docker Paris)Docker en Production (Docker Paris)
Docker en Production (Docker Paris)Jérôme Petazzoni
 
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?Membré Guillaume
 
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...Silicon Comté
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express jsAbdoulaye Dieng
 
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016Fabien Arcellier
 
Présentation CoreOS
Présentation CoreOSPrésentation CoreOS
Présentation CoreOSgcatt
 
Node.js dans Windows Azure mobile services et web sites
Node.js dans Windows Azure mobile services et web sitesNode.js dans Windows Azure mobile services et web sites
Node.js dans Windows Azure mobile services et web sitesMicrosoft
 
Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016Julia Mateo
 
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?ALTER WAY
 
Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)
Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)
Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)Publicis Sapient Engineering
 
Docker du mythe à la réalité
Docker du mythe à la réalitéDocker du mythe à la réalité
Docker du mythe à la réalitéZenika
 
Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...
Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...
Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...Publicis Sapient Engineering
 
Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !
Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !
Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !Publicis Sapient Engineering
 
Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Gonéri Le Bouder
 
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinLudovic Piot
 
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...Cédric Leblond
 

Tendances (20)

Elasticsearch 5.0 les nouveautés
Elasticsearch 5.0 les nouveautésElasticsearch 5.0 les nouveautés
Elasticsearch 5.0 les nouveautés
 
Node.js et les nouvelles technologies javascript
Node.js et les nouvelles technologies javascriptNode.js et les nouvelles technologies javascript
Node.js et les nouvelles technologies javascript
 
2014.12.11 - TECH CONF #3 - Présentation Node.js
2014.12.11 - TECH CONF #3 - Présentation Node.js2014.12.11 - TECH CONF #3 - Présentation Node.js
2014.12.11 - TECH CONF #3 - Présentation Node.js
 
Docker en Production (Docker Paris)
Docker en Production (Docker Paris)Docker en Production (Docker Paris)
Docker en Production (Docker Paris)
 
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
 
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
Introduction à Docker et utilisation en production /Digital apéro Besançon [1...
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
 
Livre blanc docker
Livre blanc docker Livre blanc docker
Livre blanc docker
 
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
 
Présentation CoreOS
Présentation CoreOSPrésentation CoreOS
Présentation CoreOS
 
Node.js dans Windows Azure mobile services et web sites
Node.js dans Windows Azure mobile services et web sitesNode.js dans Windows Azure mobile services et web sites
Node.js dans Windows Azure mobile services et web sites
 
Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016
 
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?
 
Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)
Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)
Paris Container Day 2016 : Les nouveaux défis du déploiement (Xebia Labs)
 
Docker du mythe à la réalité
Docker du mythe à la réalitéDocker du mythe à la réalité
Docker du mythe à la réalité
 
Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...
Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...
Paris Container Day 2016 : Conteneurisation de l’usine logicielle (Retour d'e...
 
Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !
Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !
Devoxx France : Kubernetes University, Cap sur l’orchestration Docker !
 
Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02
 
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
 
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
 

En vedette

Vert.x v3 - high performance polyglot application toolkit
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkitSages
 
Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app...
 	Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app... 	Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app...
Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app...Anna Shymchenko
 
Vert.x using Groovy - Simplifying non-blocking code
Vert.x using Groovy - Simplifying non-blocking codeVert.x using Groovy - Simplifying non-blocking code
Vert.x using Groovy - Simplifying non-blocking codesascha_klein
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingAlex Derkach
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
vert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMvert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMjbandi
 
Building microservices with vert.x 3.0
Building microservices with vert.x 3.0Building microservices with vert.x 3.0
Building microservices with vert.x 3.0Agraj Mangal
 
Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Vert.X: Microservices Were Never So Easy (Clement Escoffier)Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Vert.X: Microservices Were Never So Easy (Clement Escoffier)Red Hat Developers
 
h-ubu - An industrial-strength service-oriented component model for JavaScrip...
h-ubu - An industrial-strength service-oriented component model for JavaScrip...h-ubu - An industrial-strength service-oriented component model for JavaScrip...
h-ubu - An industrial-strength service-oriented component model for JavaScrip...Clément Escoffier
 
Modularity and Dynamism - The tale of two sisters
Modularity and Dynamism - The tale of two sistersModularity and Dynamism - The tale of two sisters
Modularity and Dynamism - The tale of two sistersClément Escoffier
 
vert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Javavert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in JavaClément Escoffier
 

En vedette (15)

Vert.x v3 - high performance polyglot application toolkit
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkit
 
Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app...
 	Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app... 	Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app...
Максим Сабарня и Иван Дрижирук “Vert.x – tool-kit for building reactive app...
 
Vertx
VertxVertx
Vertx
 
Vert.x using Groovy - Simplifying non-blocking code
Vert.x using Groovy - Simplifying non-blocking codeVert.x using Groovy - Simplifying non-blocking code
Vert.x using Groovy - Simplifying non-blocking code
 
Vert.x
Vert.xVert.x
Vert.x
 
Vert.x devoxx london 2013
Vert.x devoxx london 2013Vert.x devoxx london 2013
Vert.x devoxx london 2013
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
 
Production ready Vert.x
Production ready Vert.xProduction ready Vert.x
Production ready Vert.x
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
vert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMvert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVM
 
Building microservices with vert.x 3.0
Building microservices with vert.x 3.0Building microservices with vert.x 3.0
Building microservices with vert.x 3.0
 
Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Vert.X: Microservices Were Never So Easy (Clement Escoffier)Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Vert.X: Microservices Were Never So Easy (Clement Escoffier)
 
h-ubu - An industrial-strength service-oriented component model for JavaScrip...
h-ubu - An industrial-strength service-oriented component model for JavaScrip...h-ubu - An industrial-strength service-oriented component model for JavaScrip...
h-ubu - An industrial-strength service-oriented component model for JavaScrip...
 
Modularity and Dynamism - The tale of two sisters
Modularity and Dynamism - The tale of two sistersModularity and Dynamism - The tale of two sisters
Modularity and Dynamism - The tale of two sisters
 
vert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Javavert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Java
 

Similaire à Vert.x

HTML5... La révolution maintenant!
HTML5... La révolution maintenant!HTML5... La révolution maintenant!
HTML5... La révolution maintenant!CARA_Lyon
 
HTML5... La révolution maintenant!
HTML5... La révolution maintenant!HTML5... La révolution maintenant!
HTML5... La révolution maintenant!CARA_Lyon
 
Introduction aux RIA (Rich Internet Applications)
Introduction aux RIA (Rich Internet Applications)Introduction aux RIA (Rich Internet Applications)
Introduction aux RIA (Rich Internet Applications)Tugdual Grall
 
Retours Devoxx France 2016
Retours Devoxx France 2016Retours Devoxx France 2016
Retours Devoxx France 2016Antoine Rey
 
La mobilité dans Drupal
La mobilité dans DrupalLa mobilité dans Drupal
La mobilité dans DrupalAdyax
 
Flex, une techno RIA incontournable pour les futures app web ?
Flex, une techno RIA incontournable pour les futures app web ?Flex, une techno RIA incontournable pour les futures app web ?
Flex, une techno RIA incontournable pour les futures app web ?GreenIvory
 
ENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - CoursENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - CoursHoracio Gonzalez
 
Enib cours c.a.i. web - séance #6 : introduction à node js
Enib   cours c.a.i. web - séance #6 : introduction à node jsEnib   cours c.a.i. web - séance #6 : introduction à node js
Enib cours c.a.i. web - séance #6 : introduction à node jsHoracio Gonzalez
 
Dotnet j2 ee
Dotnet j2 eeDotnet j2 ee
Dotnet j2 eechdalel
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Jean-Laurent de Morlhon
 
BordeauxJUG : Portails &amp; Portlets Java
BordeauxJUG : Portails &amp; Portlets JavaBordeauxJUG : Portails &amp; Portlets Java
BordeauxJUG : Portails &amp; Portlets JavaCamblor Frédéric
 
Activity
ActivityActivity
Activitydido
 
ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3
ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3
ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3Horacio Gonzalez
 
Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...
Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...
Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...sametmax
 
Les nouveautés du Framework .NET 4.5
Les nouveautés du Framework .NET 4.5Les nouveautés du Framework .NET 4.5
Les nouveautés du Framework .NET 4.5Microsoft
 
Node.js, le pavé dans la mare
Node.js, le pavé dans la mareNode.js, le pavé dans la mare
Node.js, le pavé dans la mareValtech
 
Programmation web asynchrone avec Tornado
Programmation web asynchrone avec TornadoProgrammation web asynchrone avec Tornado
Programmation web asynchrone avec TornadoRonan Amicel
 

Similaire à Vert.x (20)

HTML5... La révolution maintenant!
HTML5... La révolution maintenant!HTML5... La révolution maintenant!
HTML5... La révolution maintenant!
 
HTML5... La révolution maintenant!
HTML5... La révolution maintenant!HTML5... La révolution maintenant!
HTML5... La révolution maintenant!
 
Introduction aux RIA (Rich Internet Applications)
Introduction aux RIA (Rich Internet Applications)Introduction aux RIA (Rich Internet Applications)
Introduction aux RIA (Rich Internet Applications)
 
Retours Devoxx France 2016
Retours Devoxx France 2016Retours Devoxx France 2016
Retours Devoxx France 2016
 
HTML5 en projet
HTML5 en projetHTML5 en projet
HTML5 en projet
 
La mobilité dans Drupal
La mobilité dans DrupalLa mobilité dans Drupal
La mobilité dans Drupal
 
Flex, une techno RIA incontournable pour les futures app web ?
Flex, une techno RIA incontournable pour les futures app web ?Flex, une techno RIA incontournable pour les futures app web ?
Flex, une techno RIA incontournable pour les futures app web ?
 
ENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - CoursENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
 
12-Factor
12-Factor12-Factor
12-Factor
 
Enib cours c.a.i. web - séance #6 : introduction à node js
Enib   cours c.a.i. web - séance #6 : introduction à node jsEnib   cours c.a.i. web - séance #6 : introduction à node js
Enib cours c.a.i. web - séance #6 : introduction à node js
 
Dotnet j2 ee
Dotnet j2 eeDotnet j2 ee
Dotnet j2 ee
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
 
BordeauxJUG : Portails &amp; Portlets Java
BordeauxJUG : Portails &amp; Portlets JavaBordeauxJUG : Portails &amp; Portlets Java
BordeauxJUG : Portails &amp; Portlets Java
 
Activity
ActivityActivity
Activity
 
ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3
ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3
ENIB 2013-2014 - CAI Web #1: Côté navigateur 1/3
 
nodejs vs vertx
nodejs vs vertxnodejs vs vertx
nodejs vs vertx
 
Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...
Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...
Présentation de WAMP.ws, le protocole pour faire du PUB/SUB et RPC over Webso...
 
Les nouveautés du Framework .NET 4.5
Les nouveautés du Framework .NET 4.5Les nouveautés du Framework .NET 4.5
Les nouveautés du Framework .NET 4.5
 
Node.js, le pavé dans la mare
Node.js, le pavé dans la mareNode.js, le pavé dans la mare
Node.js, le pavé dans la mare
 
Programmation web asynchrone avec Tornado
Programmation web asynchrone avec TornadoProgrammation web asynchrone avec Tornado
Programmation web asynchrone avec Tornado
 

Plus de Xavier MARIN

BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesBreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesXavier MARIN
 
Warp 10 - The most advanced Time Series Platform
Warp 10 - The most advanced Time Series PlatformWarp 10 - The most advanced Time Series Platform
Warp 10 - The most advanced Time Series PlatformXavier MARIN
 
Jeux vidéo sur mobile - Unity3d
Jeux vidéo sur mobile - Unity3dJeux vidéo sur mobile - Unity3d
Jeux vidéo sur mobile - Unity3dXavier MARIN
 
FinistJUG - Camel Presentation
FinistJUG - Camel PresentationFinistJUG - Camel Presentation
FinistJUG - Camel PresentationXavier MARIN
 

Plus de Xavier MARIN (6)

BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesBreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
 
Warp 10 - The most advanced Time Series Platform
Warp 10 - The most advanced Time Series PlatformWarp 10 - The most advanced Time Series Platform
Warp 10 - The most advanced Time Series Platform
 
Mongo db et nosql
Mongo db et nosqlMongo db et nosql
Mongo db et nosql
 
Polymer
PolymerPolymer
Polymer
 
Jeux vidéo sur mobile - Unity3d
Jeux vidéo sur mobile - Unity3dJeux vidéo sur mobile - Unity3d
Jeux vidéo sur mobile - Unity3d
 
FinistJUG - Camel Presentation
FinistJUG - Camel PresentationFinistJUG - Camel Presentation
FinistJUG - Camel Presentation
 

Vert.x

  • 1. Vert.X high performance polyglot application toolkit
  • 3. Petite histoire ● Créé par Tim Fox @timfox ● en 2011 chez VMWare ● sous le nom de Node.x ● 2012 : devient Vert.X ● 2013 : passe dans la fondation Eclipse ● 24/06/2015 sortie de la v3 ● environ 180 contributeurs https://www.parleys.com/search/vert.x/PRESENTATIONS
  • 4. Vocabulaire pour commerciaux Simple threadSafe concurrent asynchronous eventDriven reactive eventBus over a scalable polyglot embeddable toolkit plateform
  • 5. Le problème ● Répondre à un grand nombre de clients en même temps ● C10k = 10 000 connexions simultanées
  • 8. Multi Thread vs Mono Thread + boucle d’événement
  • 9. Multi Thread vs Mono Thread + boucle d’événement J2EE Mono Thread + boucle d’événement Statique EJB JSP Servlet Traitement TPL Statique x x x x JBoss WebSphere Tomee
  • 10. Multi Thread vs Mono Thread + boucle d’événement J2EE Mono Thread + boucle d’événement Statique EJB JSP Servlet Traitement TPL Statique x x x x JBoss WebSphere Tomee x x x Tomcat
  • 11. Multi Thread vs Mono Thread + boucle d’événement J2EE Mono Thread + boucle d’événement Statique EJB JSP Servlet Traitement TPL Statique x x x x JBoss WebSphere Tomee x x x Tomcat x x Jetty
  • 12. Multi Thread vs Mono Thread + boucle d’événement J2EE Mono Thread + boucle d’événement Statique EJB JSP Servlet Traitement TPL Statique x x x x JBoss WebSphere Tomee x x x Tomcat x x Jetty Serveur HTTP x Apache HTTPD
  • 13. Multi Thread vs Mono Thread + boucle d’événement J2EE Mono Thread + boucle d’événement Statique EJB JSP Servlet Traitement TPL Statique x x x x JBoss WebSphere Tomee NodeJS x x x x x x Tomcat Vert.X x x x x x Jetty Lagom x x x Serveur HTTP x Apache HTTPD NginX x
  • 14. Système réactif vs programmation réactive Les applications modernes font face à de nouveaux défis, bla bla bla Responsive : répond sur un laps de temps Résilient : répond même en cas d’ échec Elastique : répond quel que soit la charge Message-driven : repose sur le la communication événementielle asynchrone http://www.reactivemanifesto.org
  • 15. Caractéristiques Réactif ● Responsive ○ Tient la charge (scalable) ○ Robuste (resilience) ● Message-driven ○ événementiel asynchrone Polyglotte ● Pas que en Java ○ Groovy, Ruby, Javascript ● S’exécute sur la VM Handler Event Loop Handler Handler Handler Handler Les handlers sont toujours appelés dans le même thread (event loop) Les handlers ne bloquent jamais le thread qui les appelle message-driven reactor pattern
  • 16. Qu’est-ce que ? ● Un message ● Une notification ● Une requête HTTP ● Une commande, une instruction ● Un fichier ● Un résultat, un rapport, une erreur Event Loop Handler Handler Handler Handler void operation(param1, param2, Handler< > { // … handler.handle( ); // … } void handle( ) { // faire un truc avec }
  • 17. Modèle de développement asynchrone vertx.createHttpServer() .requestHandler( req -> req.response().end("Hello there!") ) .listen(8080, ar -> { if (ar.failed()) { System.out.println("The server failed to start"); } else { System.out.println("Server started on 8080"); } } ); ar : AsyncResult ● status : success ou failed ● result : si success ● cause : si failed
  • 18. JVM polyglotte Dois-je coder en java pour exécuter un programme sur la JVM? Oui, mais pas que, fais-toi plaisir!
  • 19. JVM polyglotte On peut programmer en plus de 200 langages Java, JavaFX, Ceylon, Gosu, Groovy, Clojure, Rhino Nashorn, Mirah, Scala, JRuby, Xtend, JPython, Fantom, Oxygene, Kotlin, … L’intérêt : à chaque problème sa solution “Quand on n’a qu’un marteau dans la main, les vis ressemblent à des clous”
  • 20. Polyglotte var vertx = require('vertx-js/vertx'); var server = vertx.createHttpServer(); server.requestHandler(function (request) { var response = request.response(); response.putHeader('content-type', 'text/plain'); response.end('Hello World!'); }); server.listen(8080);
  • 21. Polyglotte server = vertx.create_http_server() server.request_handler() { |request| response = request.response() response.put_header("content-type", "text/plain") response.end("Hello World!") } server.listen(8080)
  • 22. Polyglotte def server = vertx.createHttpServer() server.requestHandler({ request -> def response = request.response() response.putHeader("content-type", "text/plain") response.end("Hello World!") }) server.listen(8080)
  • 23. Polyglotte public class Main { public static void main(String[] args) { HttpServer server = vertx.createHttpServer(); server.requestHandler(request -> { HttpServerResponse response = request.response(); response.putHeader("content-type", "text/plain"); response.end("Hello World!"); }); server.listen(8080); } }
  • 24. L’event bus ● Point à point ● Publish / Subscribe ● Requête / réponse Les messages sont reçus par des handlers et déposés en utilisant l’eventLoop Chaque instance de Vert.X a accès à l’eventBus Event Bus
  • 26. Bus Architecture instance instance instance instance Processeur Multi-instances
  • 27. Bus Architecture Machine 1 Machine 2 Machine 3 Cluster
  • 28. L’event bus L’eventBus permet une communication distribuée. Presque tout peut publier un message sur le bus. Event Bus Machine 1 Machine 2 Machine 3 Machine 4 Node Bin
  • 29. Event bus EventBus eb = vertx.eventBus(); MessageConsumer<String> consumer = eb.consumer("news.uk.sport", message -> { System.out.println("I have received a message: " + message.body()); message.reply("how interesting!"); }).completionHandler(res -> { if (res.succeeded()) { System.out.println("Registration has reached all nodes"); } else { System.out.println("Registration failed!"); } }); consumer.unregister(res -> { if (res.succeeded()) { System.out.println("Un-registration has reached all nodes"); } else { System.out.println("Un-registration failed!"); } });
  • 30. Event bus Publish / Subscribe eventBus.publish("news.uk.sport", "You kicked a ball"); Point à point eventBus.send("news.uk.sport","You kicked a ball",ar ->{ if (ar.succeeded()) { System.out.println("reply: " + ar.result().body()); } }); Ajout d'en-tête DeliveryOptions options = new DeliveryOptions(); options.addHeader("some-header", "some-value"); eventBus.send("news.uk.sport", "You kicked a ball", options);
  • 31. Verticles : un modèle “agent” ou presque Les verticles sont des bouts de code qui sont déployés et exécuté par Vert.X peu importe le langage. vertx.deployVerticle("mon.verticle"); Ils ont un cycle de vie : start et stop. Ils interagissent en utilisant des événement ou des messages. Ils peuvent être instanciés plusieurs fois et se respawn en cas d’échec. Les workerVerticles traitent le bloquant Verticle Event Bus Handler Handler vertx.deployVerticle("mon.verticle", new DeploymentOptions().setInstances(3));
  • 32. Verticles : un modèle “agent” ou presque Les verticles morts sont redémarés sur un autre noeud du cluster. Verticle Event Bus Handler Handler vertx.deployVerticle("mon.verticle", new DeploymentOptions().setHA(true)); Machine 1 Machine 2 Machine 3 FailOver
  • 34. Stack Vert.X http://vertx.io/docs/ core Web JDBC Redis Auth Mongo JSClient Stomp Mail JCA Metrics Rx Sync Shell docker SockJS Bridge Services proxies
  • 35. Stack Vert.X ● Vert.x core ● Vert.x Web ○ Routages et sous-routages ○ Sessions ○ Cookies ○ Sécurité (basic auth, shiro, JWT, …) ○ Templates (Handlebars, Jade, MVEL, Thymeleaf) ○ SockJS ○ Static files ○ … ● Accès aux données ○ MongoDB, JDBC, Redis, SQL Common ● Intégration ○ Mail et JCA ● Sécurité ○ basic auth, shiro, JWT, JDBC Auth ● Reactive ○ Vert.X Rx, Reactive streams ● Metrics ● Vert.X unit
  • 36. Accès aux données de manière asynchrone jdbc.getConnection(ar -> { SQLConnection connection = ar.result(); connection.query("SELECT * FROM Beer", resp -> { if (!resp.failed()) { List<Beer> beverages = resp.result() .getRows() .stream() .map(Beer::new) .collect(Collectors.toList()); } //… }); });
  • 37. Le Web HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); Route route = router.route(HttpMethod.PUT, "myapi/orders") .consumes("application/json") .produces("application/json"); route.handler(routingContext -> { // This would be match for any PUT method to paths starting with // "myapi/orders" with a content-type of "application/json" // and an accept header matching "application/json" }); server.requestHandler(router::accept).listen(8080); HTTP server Router Handler Handler réponse HTTP requête HTTP
  • 38. Le Web Router restAPI = Router.router(vertx); restAPI.get("/products/:productID").handler(rc -> { // TODO Handle the lookup of the product.... rc.response().write(productJSON); }); restAPI.put("/products/:productID").handler(rc -> { // TODO Add a new product… rc.response().end(); }); Router mainRouter = Router.router(vertx); // Handle static resources mainRouter.route("/static/*").handler(StaticHandler.create()); mainRouter.route(".*.templ").handler(myTemplateHandler); mainRouter.mountSubRouter("/productsAPI", restAPI); $curl http://localhost:8080/productsAPI/products/1234
  • 39. Le Web router.route().path("/*") .consumes("application/json") .handler(routingContext -> { HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "application/json"); routingContext.next(); }); router.get("/beers/").handler(routingContext -> { JsonObject query = new JsonObject(); mongoClient.find("beers", query, res -> { if (res.succeeded()) { JsonArray jar = new JsonArray(); res.result().forEach(jar::add); routingContext.response().end(jar.encodePrettily()); } else { res.cause().printStackTrace(); } }); }
  • 40. Micro services Les micro-services interagissent en utilisant l’eventBus ou en utilisant un autre protocole. Des service-proxies sont générés pour l’eventBus. On peut même consommer les services depuis NodeJS, le navigateur, iOS ou Android via l’eventBus. Chaque service peut se mettre à l’ échelle en fonction de la charge et supporte le fail-over. Service Event Bus Service Service Packagé dans un fat-jar HTTP/REST AMQP Service proxy
  • 45. Cloud ready ● Vert.x OpenShift Cartridge ○ https://github.com/vert-x3/vertx-openshift-cartridge ● Vert.x OpenShift Using DIY Cartridge ○ https://github.com/vert-x3/vertx-openshift-diy-quickstart ● Vert.x Docker Images ○ https://github.com/vert-x3/vertx-stack/tree/master/stack-docker
  • 47. The end ... « Si vous avez compris ce que je viens de vous dire, c’est que je me suis probablement mal exprimé » A. Greenspan https://github.com/Giwi/vertx3-angular-beers