modern app programming
play

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


  1. Modern app programming with RxJava and Eclipse Vert.x #QConSP @vertx_project

  2. Who am I? Vert.x core team member since 2016 Working at since 2012 Contributing specifically to monitoring and clustering @tsegismont #QConSP @vertx_project

  3. Started in 2O12 Eclipse Vert.x Eclipse / Apache licensing A toolkit to build reactive 7K on applications on the JVM Built on top of Netty @vertx_project https://vertx.io

  4. Pay the right price ● Tiny footprint ● Do one thing and do it well ● Modular set of extensions #QConSP @vertx_project

  5. Why going reactive?

  6. A hotel room booking startup story #QConSP @vertx_project

  7. 2 0 0 0

  8. 2002

  9. 2003

  10. 2006

  11. 2009

  12. NoSQL 2011

  13. 1/ Many channels 2/ Lots of I/O

  14. while ( isRunning ) { String line = bufferedReader .readLine(); switch (line.substring(0, 4)) { case "ECHO" : bufferedWriter .write(line); break ; // ... // other cases (...) // ... } }

  15. x 1000 =

  16. “But I don’t do Internet scale. I do enterprise!”

  17. 2018 server: 28 cores, 512 GB memory

  18. Microservices

  19. Your container share: 2 vCPU, 512 MB memory

  20. 1/ Keep the number of threads to a minimum 2/ Keep them busy

  21. Thread Events Event-loop

  22. Event loops in Vert.x project

  23. 2 event-loops per core

  24. 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 -> { Verticles req.response().end( "Hello world!" ); }).listen(8080); } }

  25. DeploymentOptions options = new DeploymentOptions() .setInstances(3); vertx.deployVerticle(httpVerticle, options); Load-balancing

  26. Communication between verticles?

  27. Multi-paradigm EventBus Standalone or clustered Messaging passing, Browser and mobile bridges not shared data

  28. EventBus eventBus = vertx .eventBus(); eventBus.<String>consumer( "greeting" ).handler(msg -> { String name = msg.body(); msg.reply(String. format ( "Hello %s!" , name)); }); 2 1 EventBus eventBus = vertx .eventBus(); eventBus.<String>send( "greeting" , "QConSP" , ar -> { if (ar.succeeded()) { System. out .println(ar.result().body()); } else { ar.cause().printStackTrace(); } });

  29. Bridge Verticle

  30. Distributed EventBus demo #QConSP @vertx_project

  31. Reactive Programming with RxJava #QConSP @vertx_project

  32. Everything is a stream: data or events

  33. Java 8 streams on steroids

  34. Observable Observer Subscription Lazy and push based

  35. Request Observable Observer Subscription Backpressure

  36. Different flavors None One Many Completable Single<T> Observable<T> * plus Maybe<T> and Flowable<T> in RxJava 2 #QConSP @vertx_project

  37. Composing data flows

  38. Great to deal with failures and latencies in distributed systems

  39. Observable<String> loadPostsFromRDBMS(LocalDate date); Observable<Comment> loadFromDocumentStore(String postId); Composition loadPostsFromRDBMS(date) .concatMap(postId -> loadFromDocumentStore(postId)) .retry(4) .timeout(500, TimeUnit. MILLISECONDS ) .subscribe();

  40. No need to create your own Observables with Vert.x

  41. Rxified APIs import io.vertx.ext.web.Router; import io.vertx.reactivex.ext.web.Router; #QConSP @vertx_project

  42. Rxified APIs void listen( int port, Handler<AsyncResult<HttpServer>> handler); Single<HttpServer> rxListen( int port); #QConSP @vertx_project

  43. Rxified ReadStream<T> class AsyncFile implements ReadStream<Buffer> { // ... // RxJava1 Observable<Buffer> toObservable(); // RxJava2 Flowable<Buffer> toFlowable(); // ... } #QConSP @vertx_project

  44. Music Store demo https://github.com/tsegismont/vertx-musicstore #QConSP @vertx_project

  45. Mongo Postgres Cover Art Archive

  46. Learning #QConSP @vertx_project

  47. Learning #QConSP @vertx_project

  48. Thank you! More questions? Come to the Red Hat booth!

Recommend


More recommend