Upload
clement-escoffier
View
1.749
Download
2
Embed Size (px)
Citation preview
Be reactive on the JVM but not only in Java
Clement Escoffier, Red Hat
Reactive§Responsiveness§On various workload (elasticity)§ In the face of failures (resilience)
§Message-driven§Asynchronous message-passing
Polyglot§Not only Java§Groovy, Ruby, JavaScript
§Run on top of a JVM
Handler
Event Loop
Handlers
Handlers are alwayscalled in the samethread (the event loop)
Event Loop
Handlers
Handlers must never block the thread callingthem.
Event Loop
Event Loop
Handlers are always executed in the same event loop.
Event Loops
A Message
A Notification
A HTTP Request
A command, an instruction
A file
A result, a report, an error
void operation(param 1, param2, Handler< > handler) {
//…handler.handle( )//…
}
void handle( ) {// do something with
}
vertx.createHttpServer().requestHandler(
req -‐> req.response().end("Hello there!")).listen(8080,
ar -‐> {if (ar.failed()) {System.out.println("The HTTP Server has failed to start");
} else {System.out.println("The HTTP Server is up");
}}
);
void add(int a, int b, Handler<Integer> handler) {int r = a + b;handler.handle(r);
}
void doSomething() {add(1, 1, i -‐> {
System.out.println("result : " + i);
});//…
}
2
13
Event Bus
Point to PointPublish / SubscribeRequest / Response
Event Bus
Messages are received using Handlers and delivered using the event loop.
Event Bus
Each vert.x instance has access to the event bus.
Event Bus
The event bus allows distributed communication.
Machine 1
Machine 2Machine 3
Almost anything can send / receive messages
Machine 1
Machine 2Machine 3
binnode
Verticles are chunks of code that get deployed and run by Vert.x.
Verticle
Event Bus
Handler
vertx.deployVerticle("my.verticle");
Verticles have a lifecycle (start, stop)
Verticle
Event Bus
Handler
Verticles interact using events / messages.
Verticle
Event Bus
Handler
Verticles can be instantiated multiple times.
vertx.deployVerticle("my.verticle", new DeploymentOptions()
.setInstances(3));
Dead verticles are restarted on a running node.
Verticlesfail-over
vertx.deployVerticle("my.verticle", new DeploymentOptions()
.setHA(true));
Verticles can be written in any supported language
GroovyVerticle
JSVerticle
JavaVerticle
RubyVerticle
Polyglot
Event BusDistributed
Verticle
puts "Hello"
EventsEvent Loops
Handlers
Core
WebAuth
JDBC Redis
Mongo
Stomp
Mail JCA RX
Metrics
JS Client
Docker
OpenShift
Shell
Sync
SvcSvc
Svc
Micro-services interact using the event bus
Packaged in a fat jar
SvcSvc
Svc
HTTP /REST
TCP
or using HTTP, TCP, STOMP, AMQP
SvcSvc
Svc
Proxy generation for the event bus
Service exposed on the event busClient
SvcSvc Consumption of services
from node.js or the browser
JavaScriptClient
JS
SvcSvc
Svc
Each service scales up and down, and supports fail-over
HTTP /REST
http://vertx.io
http://vertx.io/blog/my-first-vert-x-3-application
https://github.com/vert-x3/vertx-examples