View
24
Download
0
Category
Preview:
Citation preview
#QConSP @vertx_project
Who am I?
Vert.x core team member since 2016
Working at since 2012
Contributing specifically to monitoring and clustering
@tsegismont
Eclipse Vert.xA 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
Pay the right price
● Tiny footprint● Do one thing and do it well● Modular set of extensions
while (isRunning) { String line = bufferedReader.readLine(); switch (line.substring(0, 4)) { case "ECHO": bufferedWriter.write(line); break; // ... // other cases (...) // ... }}
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
EventBusMessaging 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
#QConSP @vertx_project
Different flavors
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
Rxified APIs
import io.vertx.ext.web.Router;
import io.vertx.reactivex.ext.web.Router;
#QConSP @vertx_project
Rxified APIs
Single<HttpServer> rxListen(int port);
void listen(int port, Handler<AsyncResult<HttpServer>> handler);
#QConSP @vertx_project
Rxified ReadStream<T>
class AsyncFile implements ReadStream<Buffer> {
// ...
// RxJava1 Observable<Buffer> toObservable();
// RxJava2 Flowable<Buffer> toFlowable();
// ...
}
#QConSP @vertx_project
Music Store demo
https://github.com/tsegismont/vertx-musicstore
Recommended