vert.x 3.1 - be reactive on the jvm but not only in java

34
Be reactive on the JVM but not only in Java

Upload: clement-escoffier

Post on 14-Apr-2017

1.748 views

Category:

Software


2 download

TRANSCRIPT

Page 1: vert.x 3.1 - be reactive on the JVM but not only in Java

Be  reactive  on  the  JVM  but  not  only  in  Java

Page 2: vert.x 3.1 - be reactive on the JVM but not only in Java

Clement Escoffier, Red Hat

Page 3: vert.x 3.1 - be reactive on the JVM but not only in Java
Page 4: vert.x 3.1 - be reactive on the JVM but not only in Java

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

Page 5: vert.x 3.1 - be reactive on the JVM but not only in Java

Handler

Page 6: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Loop

Handlers

Handlers are alwayscalled in the samethread (the event loop)

Page 7: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Loop

Handlers

Handlers must never block the thread callingthem.

Page 8: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Loop

Page 9: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Loop

Page 10: vert.x 3.1 - be reactive on the JVM but not only in Java

Handlers are always executed in the same event loop.

Event Loops

Page 11: vert.x 3.1 - be reactive on the JVM but not only in Java

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

}

Page 12: vert.x 3.1 - be reactive on the JVM but not only in Java

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");

}}

);

Page 13: vert.x 3.1 - be reactive on the JVM but not only in Java

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

Page 14: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Bus

Point to PointPublish / SubscribeRequest / Response

Page 15: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Bus

Messages are received using Handlers and delivered using the event loop.

Page 16: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Bus

Each vert.x instance has access to the event bus.

Page 17: vert.x 3.1 - be reactive on the JVM but not only in Java

Event Bus

The event bus allows distributed communication.

Machine 1

Machine 2Machine 3

Page 18: vert.x 3.1 - be reactive on the JVM but not only in Java

Almost anything can send / receive messages

Machine 1

Machine 2Machine 3

binnode

Page 19: vert.x 3.1 - be reactive on the JVM but not only in Java

Verticles are chunks of code that get deployed and run by Vert.x.

Verticle

Event Bus

Handler

vertx.deployVerticle("my.verticle");

Page 20: vert.x 3.1 - be reactive on the JVM but not only in Java

Verticles have a lifecycle (start, stop)

Verticle

Event Bus

Handler

Page 21: vert.x 3.1 - be reactive on the JVM but not only in Java

Verticles interact using events / messages.

Verticle

Event Bus

Handler

Page 22: vert.x 3.1 - be reactive on the JVM but not only in Java

Verticles can be instantiated multiple times.

vertx.deployVerticle("my.verticle",  new  DeploymentOptions()

.setInstances(3));

Page 23: vert.x 3.1 - be reactive on the JVM but not only in Java

Dead verticles are restarted on a running node.

Verticlesfail-over

vertx.deployVerticle("my.verticle", new DeploymentOptions()

.setHA(true));

Page 24: vert.x 3.1 - be reactive on the JVM but not only in Java

Verticles can be written in any supported language

GroovyVerticle

JSVerticle

JavaVerticle

RubyVerticle

Page 25: vert.x 3.1 - be reactive on the JVM but not only in Java

Polyglot

Event BusDistributed

Verticle

puts  "Hello"

EventsEvent Loops

Handlers

Page 26: vert.x 3.1 - be reactive on the JVM but not only in Java
Page 27: vert.x 3.1 - be reactive on the JVM but not only in Java

Core

WebAuth

JDBC Redis

Mongo

Stomp

Mail JCA RX

Metrics

JS Client

Docker

OpenShift

Shell

Sync

Page 28: vert.x 3.1 - be reactive on the JVM but not only in Java

SvcSvc

Svc

Micro-services interact using the event bus

Packaged in a fat jar

Page 29: vert.x 3.1 - be reactive on the JVM but not only in Java

SvcSvc

Svc

HTTP /REST

TCP

or using HTTP, TCP, STOMP, AMQP

Page 30: vert.x 3.1 - be reactive on the JVM but not only in Java

SvcSvc

Svc

Proxy generation for the event bus

Service exposed on the event busClient

Page 31: vert.x 3.1 - be reactive on the JVM but not only in Java

SvcSvc Consumption of services

from node.js or the browser

JavaScriptClient

JS

Page 32: vert.x 3.1 - be reactive on the JVM but not only in Java

SvcSvc

Svc

Each service scales up and down, and supports fail-over

HTTP /REST

Page 33: vert.x 3.1 - be reactive on the JVM but not only in Java
Page 34: vert.x 3.1 - be reactive on the JVM but not only in Java

http://vertx.io

http://vertx.io/blog/my-first-vert-x-3-application

https://github.com/vert-x3/vertx-examples