#QConSP @vertx_project
Modern app programming
with RxJava and Eclipse Vert.x
Modern app programming with RxJava and Eclipse Vert.x #QConSP - - PowerPoint PPT Presentation
Modern app programming with RxJava and Eclipse Vert.x #QConSP @vertx_project Who am I? Vert.x core team member since 2016 Working at since 2012 Contributing specifically to monitoring and clustering @tsegismont
#QConSP @vertx_project
with RxJava and Eclipse Vert.x
#QConSP @vertx_project
Vert.x core team member since 2016 Working at since 2012 Contributing specifically to monitoring and clustering
@tsegismont
A toolkit to build reactive applications on the JVM
Started in 2O12 Eclipse / Apache licensing 7K on Built on top of Netty
@vertx_project https://vertx.io
#QConSP @vertx_project
#QConSP @vertx_project
while (isRunning) { String line = bufferedReader.readLine(); switch (line.substring(0, 4)) { case "ECHO": bufferedWriter.write(line); break; // ... // other cases (...) // ... } }
2018 server: 28 cores, 512 GB memory
Microservices
Your container share: 2 vCPU, 512 MB memory
Thread Events Event-loop
2 event-loops per core
class HttpServerVerticle extends AbstractVerticle { public static void main(String[] args) { Vertx vertx = Vertx.vertx(); vertx.deployVerticle(HttpServerVerticle.class.getName()); } @Override public void start() throws Exception { vertx.createHttpServer() .requestHandler(req -> { req.response().end("Hello world!"); }).listen(8080); } }
Verticles
DeploymentOptions options = new DeploymentOptions() .setInstances(3); vertx.deployVerticle(httpVerticle, options);
Load-balancing
Messaging passing, not shared data
Multi-paradigm Standalone or clustered Browser and mobile bridges
EventBus eventBus = vertx.eventBus(); eventBus.<String>consumer("greeting").handler(msg -> { String name = msg.body(); msg.reply(String.format("Hello %s!", name)); }); EventBus eventBus = vertx.eventBus(); eventBus.<String>send("greeting", "QConSP", ar -> { if (ar.succeeded()) { System.out.println(ar.result().body()); } else { ar.cause().printStackTrace(); } });
1 2
Verticle Bridge
#QConSP @vertx_project
#QConSP @vertx_project
Everything is a stream: data or events
Lazy and push based
Observable Observer Subscription
Backpressure
Observable Observer Subscription Request
#QConSP @vertx_project
None One Many Completable Single<T> Observable<T> * plus Maybe<T> and Flowable<T> in RxJava 2
Observable<String> loadPostsFromRDBMS(LocalDate date); Observable<Comment> loadFromDocumentStore(String postId); loadPostsFromRDBMS(date) .concatMap(postId -> loadFromDocumentStore(postId)) .retry(4) .timeout(500, TimeUnit.MILLISECONDS) .subscribe();
Composition
#QConSP @vertx_project
import io.vertx.ext.web.Router; import io.vertx.reactivex.ext.web.Router;
#QConSP @vertx_project
Single<HttpServer> rxListen(int port); void listen(int port, Handler<AsyncResult<HttpServer>> handler);
#QConSP @vertx_project
class AsyncFile implements ReadStream<Buffer> { // ... // RxJava1 Observable<Buffer> toObservable(); // RxJava2 Flowable<Buffer> toFlowable(); // ... }
#QConSP @vertx_project
https://github.com/tsegismont/vertx-musicstore
Mongo Postgres Cover Art Archive
#QConSP @vertx_project
#QConSP @vertx_project
More questions? Come to the Red Hat booth!