Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Vertx - Reactive & Distributed

49 views

Published on

During past years, the requirements for modern applications have increased from gigabytes of data to terabytes, from thousands of requests per second to millions, from seconds of response time to milliseconds, and this list can be continued. Until now, most of these problems have been solved using the microservices architecture, but what's next? What next approach should we apply where microservices fail? In this talk, we will overview modern approaches to application development with reactive and distributed architecture and see how Vert.x help to implement such solutions.

Published in: Technology
  • Be the first to comment

Vertx - Reactive & Distributed

  1. 1. Reactive & Distributed
  2. 2. Orkhan Gasimov Digital Transformation Architect @ GlobalLogic 15 years of software engineering; training & mentorship; author of trainings about: Microservices; Spring Cloud; Akka; 2Speaker
  3. 3. Concept & Architecture 3Agenda
  4. 4. What is Vert.x? 4Agenda
  5. 5. Why Vert.x is Reactive? 5Agenda
  6. 6. How Vert.x is Distributed? 6Agenda
  7. 7. Evolution Distributed Application Design
  8. 8. 8 Enterprise Evolution
  9. 9. 9 Enterprise App Server Evolution
  10. 10. 10 Enterprise App Server Module Module Module Module Evolution
  11. 11. 11 Enterprise Evolution App Server 1 Module Module Module Module App Server N Module Module Module Module …
  12. 12. 12 Enterprise Evolution App Server 1 Module Module Module Module App Server N Module Module Module Module Admin Server Deployment & Configuration
  13. 13. 13 Enterprise Evolution Module Module Module Module Module Module Module Module Admin Server Deployment & Configuration
  14. 14. 14 Enterprise Evolution Admin Server Deployment & Configuration App App App App App App App App
  15. 15. 15 Enterprise Evolution App App App App App App App App Discovery & Configuration Microservices
  16. 16. 16 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Discovery & Configuration Microservices
  17. 17. 17 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Server Discovery & Configuration Microservices
  18. 18. 18 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Server Modules Discovery & Configuration Microservices
  19. 19. 19 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Server Modules JDBC Discovery & Configuration Microservices
  20. 20. 20 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Server Modules JDBC ? Discovery & Configuration Microservices
  21. 21. 21 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Discovery & Configuration Microservices
  22. 22. 22 Enterprise Evolution App App App App App App App App App App App App App App App App App App App App Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Server Modules JDBC ? Discovery & Configuration Microservices
  23. 23. 23 Enterprise Evolution App App App App App App App App Discovery & Configuration Microservices
  24. 24. 24 Enterprise Evolution App App App App App App App App Microservices Microservices Discovery & Configuration
  25. 25. 25 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices
  26. 26. 26 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application
  27. 27. 27 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC
  28. 28. 28 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client
  29. 29. 29 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC
  30. 30. 30 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ?
  31. 31. 31 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ?
  32. 32. 32 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP
  33. 33. 33 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ?
  34. 34. 34 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus
  35. 35. 35 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus
  36. 36. 36 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus External Apps
  37. 37. 37 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus External Apps IoT
  38. 38. 38 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus External Apps Cloud IoT
  39. 39. 39 Enterprise Evolution Module Module Module Module Module Module Module Module Discovery & Configuration MicroservicesMicroservices Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus External Apps Polyglot Cloud IoT
  40. 40. 40Some silly slide
  41. 41. Vert.x Reactive & Distributed
  42. 42. 42What is Vert.x?
  43. 43. 43Framework Framework Your Code
  44. 44. 44Library Library Your Code
  45. 45. 45Toolkit
  46. 46. 46Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  47. 47. 47Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  48. 48. 48Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  49. 49. 49Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  50. 50. 50Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  51. 51. 51Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  52. 52. 52Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  53. 53. 53Java Example Vertx vertx = Vertx.vertx(); Router router = Router.router(vertx); JsonObject mySQLClientConfig = new JsonObject().put("host", "localhost").put("database", "test"); SQLClient sqlClient = MySQLClient.createShared(vertx, mySQLClientConfig); router.get("/hello/:name").produces("text/plain").handler(routingContext -> { String name = routingContext.pathParam("name"); HttpServerResponse response = routingContext.response(); sqlClient.updateWithParams("INSERT INTO names (name) VALUES (?)", new JsonArray().add(name), event -> { if (event.succeeded()) { response.end("Hello " + name); } else { System.out.println("Could not INSERT to database with cause: " + event.cause()); response.setStatusCode(500); response.end(); } }); }); HttpServer server = vertx.createHttpServer(); server.requestHandler(router::accept).listen(8080);
  54. 54. Reactor Pattern 54Vert.x Core Event Loop (single thread, non blocking)
  55. 55. Reactor Pattern 55Vert.x Core Event Loop (single thread, non blocking) Worker Worker Worker delegate long running jobs & IO callback
  56. 56. Multi-Reactor 56Vert.x Core Worker Worker Worker delegate long running jobs & IO callback Event Loops
  57. 57. Event Bus 57Vert.x Core Worker Worker Worker delegate long running jobs & IO callback Event Loops H H H H
  58. 58. Basic Architecture 58Vert.x Core Worker Worker Worker delegate long running jobs & IO callback Event Loops H Client Client Client H H H request response
  59. 59. Deployment Model Verticles
  60. 60. 60Verticle public class MyVerticle extends AbstractVerticle { private HttpServer server; @Override public void start(Future<Void> startFuture) { server = vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }); server.listen(8080, res -> { if (res.succeeded()) { startFuture.complete(); } else { startFuture.fail(res.cause()); } }); } @Override public void stop(Future<Void> stopFuture) { //... } }
  61. 61. 61Verticle public class MyVerticle extends AbstractVerticle { private HttpServer server; @Override public void start(Future<Void> startFuture) { server = vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }); server.listen(8080, res -> { if (res.succeeded()) { startFuture.complete(); } else { startFuture.fail(res.cause()); } }); } @Override public void stop(Future<Void> stopFuture) { //... } }
  62. 62. 62Verticle public class MyVerticle extends AbstractVerticle { private HttpServer server; @Override public void start(Future<Void> startFuture) { server = vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }); server.listen(8080, res -> { if (res.succeeded()) { startFuture.complete(); } else { startFuture.fail(res.cause()); } }); } @Override public void stop(Future<Void> stopFuture) { //... } }
  63. 63. 63Verticle public class MyVerticle extends AbstractVerticle { private HttpServer server; @Override public void start(Future<Void> startFuture) { server = vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }); server.listen(8080, res -> { if (res.succeeded()) { startFuture.complete(); } else { startFuture.fail(res.cause()); } }); } @Override public void stop(Future<Void> stopFuture) { //... } }
  64. 64. 64Verticle public class MyVerticle extends AbstractVerticle { private HttpServer server; @Override public void start(Future<Void> startFuture) { server = vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }); server.listen(8080, res -> { if (res.succeeded()) { startFuture.complete(); } else { startFuture.fail(res.cause()); } }); } @Override public void stop(Future<Void> stopFuture) { //... } }
  65. 65. 65Verticle public class MyVerticle extends AbstractVerticle { private HttpServer server; @Override public void start(Future<Void> startFuture) { server = vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }); server.listen(8080, res -> { if (res.succeeded()) { startFuture.complete(); } else { startFuture.fail(res.cause()); } }); } @Override public void stop(Future<Void> stopFuture) { //... } }
  66. 66. Standard Verticles Run on an event loop thread Verticles 66
  67. 67. Worker Verticles Run on the worker pool & never executed concurrently Verticles 67
  68. 68. Worker Verticles Run on the worker pool & never executed concurrently Verticles DeploymentOptions options = new DeploymentOptions().setWorker(true); vertx.deployVerticle("com.mycompany.MyOrderProcessorVerticle", options); 68
  69. 69. Multi-Threaded Worker Verticles Run on the worker pool & can be executed concurrently Verticles 69
  70. 70. 70Verticles Verticle Handler Handler Handler Handler Handler Handler
  71. 71. 71Verticles Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle Verticle
  72. 72. 72Event Loops Verticle Verticle Verticle Verticle Verticle Verticle Event Loop Event Loop Verticle Verticle Verticle
  73. 73. 73Event Bus Verticle EVENT BUS Verticle Verticle Verticle Verticle Verticle Event Loop Event Loop Verticle Verticle Verticle
  74. 74. 74Vert.x Runtime Verticle EVENT BUS Verticle Verticle Verticle Verticle Verticle Event Loop Event Loop Verticle Verticle Verticle
  75. 75. 75Vert.x Runtime Socket 1 … ... Socket N Verticle EVENT BUS Verticle Verticle Verticle Verticle Verticle Event Loop Event Loop Verticle Verticle Verticle
  76. 76. 76Vert.x Runtime Socket 1 … ... Socket N Verticle EVENT BUS Verticle Verticle Verticle Verticle Verticle CPU Core CPU Core Event Loop Event Loop Verticle Verticle Verticle
  77. 77. Cluster High Availability
  78. 78. High Availability 78
  79. 79. High Availability 79
  80. 80. High Availability 80
  81. 81. High Availability 81
  82. 82. High Availability 82
  83. 83. High Availability 83
  84. 84. Regions 84
  85. 85. Availability Zones 85
  86. 86. High Availability 86
  87. 87. High Availability 87
  88. 88. High Availability 88
  89. 89. High Availability 89
  90. 90. Cluster Manager Vert.x Instance Vert.x Instance Vert.x Instance 90
  91. 91. Cluster Manager Cluster Manager Vert.x Instance Vert.x Instance Vert.x Instance 91
  92. 92. Default: Hazelcast Cluster Manager Cluster Manager Vert.x Instance Vert.x Instance Vert.x Instance 92
  93. 93. Default: Hazelcast Alternatives: Infinispan Ignite Zookeper Cluster Manager Cluster Manager Vert.x Instance Vert.x Instance Vert.x Instance 93
  94. 94. Default: Hazelcast Alternatives: Infinispan Ignite Zookeper 3rd party: Atomix & etc. Cluster Manager Cluster Manager Vert.x Instance Vert.x Instance Vert.x Instance 94
  95. 95. $ vertx run myVerticle -ha Fail-Over Vert.x Instance 1 Vert.x Instance N ... Verticle 95
  96. 96. $ vertx run myVerticle -ha Fail-Over Vert.x Instance 1 Vert.x Instance N ... Verticle 96
  97. 97. $ vertx run myVerticle -ha Fail-Over Vert.x Instance 1 Vert.x Instance N ... Verticle 97
  98. 98. $ vertx run myVerticle -ha -hagroup group-1 Groups Group-1 Vert.x Instance 1 Vert.x Instance N Group-2 Vert.x Instance 1 Vert.x Instance N ... ... Verticle Verticle 98
  99. 99. $ vertx run myVerticle -ha -hagroup group-1 Groups Group 1 Vert.x Instance 1 Vert.x Instance N Group 2 Vert.x Instance 1 Vert.x Instance N ... ... Verticle Verticle 99
  100. 100. $ vertx run myVerticle -ha -hagroup group-1 Groups Group 1 Vert.x Instance 1 Vert.x Instance N Group 2 Vert.x Instance 1 Vert.x Instance N ... ... Verticle Verticle 100
  101. 101. $ vertx run myVerticle -ha -quorum 3 Quorum Vert.x Instance 2 Vert.x Instance 3 Verticle Verticle Vert.x Instance 1 Verticle 101
  102. 102. $ vertx run myVerticle -ha -quorum 3 Quorum Vert.x Instance 1 Vert.x Instance 2 Verticle Vert.x Instance 3 Verticle Verticle 102
  103. 103. $ vertx run myVerticle -ha -quorum 3 Quorum Vert.x Instance 1 Vert.x Instance 2 Vert.x Instance 3 103
  104. 104. $ vertx run myVerticle -ha -quorum 3 Quorum Vert.x Instance 2 Vert.x Instance 3 Vert.x Instance 1 104
  105. 105. $ vertx run myVerticle -ha -quorum 3 Quorum Vert.x Instance 2 Vert.x Instance 3 Verticle Verticle Vert.x Instance 1 Verticle 105
  106. 106. Round-robin by default Load Balancing Verticle Verticle Verticle Verticle VerticleVerticle 1 2 3 106
  107. 107. Shared Data
  108. 108. SharedData sd = vertx.sharedData(); //Local LocalMap<String, String> localMap = sd.getLocalMap("myLocalMap"); localMap.put("foo", "bar"); String val = localMap.get("foo"); //Async sd.<String, String>getAsyncMap("myAsyncMap", res -> { if (res.succeeded()) { AsyncMap<String, String> asyncMap = res.result(); } else { //fail } }); Maps 108
  109. 109. SharedData sd = vertx.sharedData(); //Local LocalMap<String, String> localMap = sd.getLocalMap("myLocalMap"); localMap.put("foo", "bar"); String val = localMap.get("foo"); //Async sd.<String, String>getAsyncMap("myAsyncMap", res -> { if (res.succeeded()) { AsyncMap<String, String> asyncMap = res.result(); } else { //fail } }); Maps 109
  110. 110. SharedData sd = vertx.sharedData(); //Local LocalMap<String, String> localMap = sd.getLocalMap("myLocalMap"); localMap.put("foo", "bar"); String val = localMap.get("foo"); //Async sd.<String, String>getAsyncMap("myAsyncMap", res -> { if (res.succeeded()) { AsyncMap<String, String> asyncMap = res.result(); } else { //fail } }); Maps 110
  111. 111. ... //Async get asyncMap.put("foo", "bar", resPut -> { if (resPut.succeeded()) { /*success*/ } else { /*fail*/ } }); //Async put asyncMap.get("foo", resGet -> { if (resGet.succeeded()) { Object val = resGet.result(); } else { //fail } }); Maps 111
  112. 112. ... //Async get asyncMap.put("foo", "bar", resPut -> { if (resPut.succeeded()) { /*success*/ } else { /*fail*/ } }); //Async put asyncMap.get("foo", resGet -> { if (resGet.succeeded()) { Object val = resGet.result(); } else { //fail } }); Maps 112
  113. 113. sd.getLock("mylock", res -> { if (res.succeeded()) { Lock lock = res.result(); // 5 seconds later we release the lock so someone else can get it vertx.setTimer(5000, tid -> lock.release()); } else { // Something went wrong } }); sd.getLockWithTimeout("mylock", 10000, res -> { if (res.succeeded()) { Lock lock = res.result(); } else { // Failed to get lock } }); Locks 113
  114. 114. sd.getLock("mylock", res -> { if (res.succeeded()) { Lock lock = res.result(); // 5 seconds later we release the lock so someone else can get it vertx.setTimer(5000, tid -> lock.release()); } else { // Something went wrong } }); sd.getLockWithTimeout("mylock", 10000, res -> { if (res.succeeded()) { Lock lock = res.result(); } else { // Failed to get lock } }); Locks 114
  115. 115. sd.getCounter("mycounter", res -> { if (res.succeeded()) { Counter counter = res.result(); } else { // Something went wrong! } }); Counters 115
  116. 116. Other Features Vert.x Core
  117. 117. • File System Other Core Features 117
  118. 118. • File System • TCP Servers & Clients Other Core Features 118
  119. 119. • File System • TCP Servers & Clients • HTTP Servers & Clients Other Core Features 119
  120. 120. • File System • TCP Servers & Clients • HTTP Servers & Clients • UDP Servers & Clients Other Core Features 120
  121. 121. • File System • TCP Servers & Clients • HTTP Servers & Clients • UDP Servers & Clients • DNS Client Other Core Features 121
  122. 122. • File System • TCP Servers & Clients • HTTP Servers & Clients • UDP Servers & Clients • DNS Client • Launcher (fat jars) Other Core Features 122
  123. 123. Web Server & Clients
  124. 124. HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); router.post("/entity/:id").handler(routingContext -> { // This handler will be called for every request HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/plain"); // Write to the response and end it response.end("Hello World from Vert.x-Web!"); }); server.requestHandler(router::accept).listen(8080); Web Server 124
  125. 125. HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); router.post("/entity/:id").handler(routingContext -> { // This handler will be called for every request HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/plain"); // Write to the response and end it response.end("Hello World from Vert.x-Web!"); }); server.requestHandler(router::accept).listen(8080); Web Server 125
  126. 126. HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); router.post("/entity/:id").handler(routingContext -> { // This handler will be called for every request HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/plain"); // Write to the response and end it response.end("Hello World from Vert.x-Web!"); }); server.requestHandler(router::accept).listen(8080); Web Server 126
  127. 127. HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); router.post("/entity/:id").handler(routingContext -> { // This handler will be called for every request HttpServerResponse response = routingContext.response(); response.putHeader("content-type", "text/plain"); // Write to the response and end it response.end("Hello World from Vert.x-Web!"); }); server.requestHandler(router::accept).listen(8080); Web Server 127
  128. 128. WebClient client = WebClient.create(vertx); client .get(8080, "myserver.mycompany.com", "/some-uri") .timeout(5000) .addQueryParam("param", "param_value") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); System.out.println("Received response with status code" + response.statusCode()); } else { System.out.println("Something went wrong " + ar.cause().getMessage()); } }); Web Client 128
  129. 129. WebClient client = WebClient.create(vertx); client .get(8080, "myserver.mycompany.com", "/some-uri") .timeout(5000) .addQueryParam("param", "param_value") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); System.out.println("Received response with status code" + response.statusCode()); } else { System.out.println("Something went wrong " + ar.cause().getMessage()); } }); Web Client 129
  130. 130. WebClient client = WebClient.create(vertx); client .get(8080, "myserver.mycompany.com", "/some-uri") .timeout(5000) .addQueryParam("param", "param_value") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); System.out.println("Received response with status code" + response.statusCode()); } else { System.out.println("Something went wrong " + ar.cause().getMessage()); } }); Web Client 130
  131. 131. WebClient client = WebClient.create(vertx); client .get(8080, "myserver.mycompany.com", "/some-uri") .timeout(5000) .addQueryParam("param", "param_value") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); System.out.println("Received response with status code" + response.statusCode()); } else { System.out.println("Something went wrong " + ar.cause().getMessage()); } }); Web Client 131
  132. 132. WebClient client = WebClient.create(vertx); client .get(8080, "myserver.mycompany.com", "/some-uri") .timeout(5000) .addQueryParam("param", "param_value") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); System.out.println("Received response with status code" + response.statusCode()); } else { System.out.println("Something went wrong " + ar.cause().getMessage()); } }); Web Client 132
  133. 133. WebClient client = WebClient.create(vertx); client .get(8080, "myserver.mycompany.com", "/some-uri") .timeout(5000) .addQueryParam("param", "param_value") .send(ar -> { if (ar.succeeded()) { // Obtain response HttpResponse<Buffer> response = ar.result(); System.out.println("Received response with status code" + response.statusCode()); } else { System.out.println("Something went wrong " + ar.cause().getMessage()); } }); Web Client 133
  134. 134. client .post(8080, "myserver.mycompany.com", "/some-uri") .sendJsonObject(new JsonObject() .put("firstName", "Dale") .put("lastName", "Cooper"), ar -> { if (ar.succeeded()) { // Ok } }); client .post(8080, "myserver.mycompany.com", "/some-uri") .sendJson(new User("Dale", "Cooper"), ar -> { if (ar.succeeded()) { // Ok } }); Web Client 134
  135. 135. client .post(8080, "myserver.mycompany.com", "/some-uri") .sendJsonObject(new JsonObject() .put("firstName", "Dale") .put("lastName", "Cooper"), ar -> { if (ar.succeeded()) { // Ok } }); client .post(8080, "myserver.mycompany.com", "/some-uri") .sendJson(new User("Dale", "Cooper"), ar -> { if (ar.succeeded()) { // Ok } }); Web Client 135
  136. 136. HTTP Request Validation API Contract 136
  137. 137. HTTP Request Validation OpenAPI 3 Support (with automatic requests validation) API Contract 137
  138. 138. Auth Authentication & Authorization
  139. 139. • OAuth 2 • JWT • Apache Shiro • JDBC • MongoDB • .htdigest • ... your implementation Auth Prodivers 139
  140. 140. router.route("/private/somepath").handler(routingContext -> { User user = routingContext.user(); user.isAuthorised("permission_or_authority", event -> { //async handler }); user.isAuthorised("role:role_name", event -> { //async handler }); }); Auth 140
  141. 141. router.route("/private/somepath").handler(routingContext -> { User user = routingContext.user(); user.isAuthorised("permission_or_authority", event -> { //async handler }); user.isAuthorised("role:role_name", event -> { //async handler }); }); Auth 141
  142. 142. router.route("/private/somepath").handler(routingContext -> { User user = routingContext.user(); user.isAuthorised("permission_or_authority", event -> { //async handler }); user.isAuthorised("role:role_name", event -> { //async handler }); }); Auth 142
  143. 143. Microservices
  144. 144. Microservices Sales 144
  145. 145. Microservices Sales Users 145
  146. 146. Microservices Sales WarehouseUsers 146
  147. 147. Microservices Sales WarehouseUsers DB 147
  148. 148. Microservices Sales Accounting WarehouseUsers DB 148
  149. 149. Microservices Sales Accounting WarehouseUsers StoresDB 149
  150. 150. Microservices Sales Accounting WarehouseUsers Stores HTTP HTTP HTTP HTTP HTTP DB SQL 150
  151. 151. Microservices Sales Accounting WarehouseUsers Stores HTTP DB SQL 151
  152. 152. Microservices Sales Accounting WarehouseUsers Stores HTTP DB SQL 152
  153. 153. • Publish & Discover • HTTP Endpoints Service Discovery Sales Accounting WarehouseUsers Stores HTTP DB SQL 153
  154. 154. • Publish & Discover • HTTP Endpoints • Data Sources Service Discovery Sales Accounting WarehouseUsers Stores HTTP DB SQL 154
  155. 155. • Publish & Discover • HTTP Endpoints • Data Sources • Event Bus Services Service Discovery Sales Accounting WarehouseUsers Stores HTTP DB SQL 155
  156. 156. • Publish & Discover • HTTP Endpoints • Data Sources • Event Bus Services • Anything you can imagine Service Discovery Sales Accounting WarehouseUsers Stores HTTP DB SQL 156
  157. 157. Circuit Breaker 157 Closed Success
  158. 158. Circuit Breaker 158 Closed Open Success Too many fails
  159. 159. Circuit Breaker 159 Closed Open Success Too many fails Fast Fail
  160. 160. Circuit Breaker 160 Closed Open Half-Open Success Too many fails Fast Fail Try one request
  161. 161. Circuit Breaker 161 Closed Open Half-Open Success Too many fails Fast Fail Try one request Fail
  162. 162. Circuit Breaker 162 Closed Open Half-Open Success Too many fails Fast Fail Try one request Fail Success
  163. 163. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx, new CircuitBreakerOptions() .setMaxFailures(5) // number of failure before opening the circuit .setTimeout(2000) // consider a failure if the operation does not succeed in time .setFallbackOnFailure(true) // do we call the fallback on failure .setResetTimeout(10000) // time spent in open state before attempting to re-try ); breaker.execute(future -> { // future.complete(“success") // future.fail("cause") }).setHandler(ar -> { // Get the operation result. }); Circuit Breaker 163
  164. 164. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx, new CircuitBreakerOptions() .setMaxFailures(5) // number of failure before opening the circuit .setTimeout(2000) // consider a failure if the operation does not succeed in time .setFallbackOnFailure(true) // do we call the fallback on failure .setResetTimeout(10000) // time spent in open state before attempting to re-try ); breaker.execute(future -> { // future.complete(“success") // future.fail("cause") }).setHandler(ar -> { // Get the operation result. }); Circuit Breaker 164
  165. 165. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx, new CircuitBreakerOptions() .setMaxFailures(5) // number of failure before opening the circuit .setTimeout(2000) // consider a failure if the operation does not succeed in time .setFallbackOnFailure(true) // do we call the fallback on failure .setResetTimeout(10000) // time spent in open state before attempting to re-try ); breaker.execute(future -> { // future.complete(“success") // future.fail("cause") }).setHandler(ar -> { // Get the operation result. }); Circuit Breaker 165
  166. 166. CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx, new CircuitBreakerOptions() .setMaxFailures(5) // number of failure before opening the circuit .setTimeout(2000) // consider a failure if the operation does not succeed in time .setFallbackOnFailure(true) // do we call the fallback on failure .setResetTimeout(10000) // time spent in open state before attempting to re-try ); breaker.executeWithFallback(future -> { // future.complete(“success") // future.fail("cause") }, th -> { // Fallback return "Hello"; }).setHandler(ar -> { // Get the operation result. }); Circuit Breaker 166
  167. 167. • Formats • Properties • JSON • YAML • etc. Config 167
  168. 168. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory 168
  169. 169. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables 169
  170. 170. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties 170
  171. 171. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP 171
  172. 172. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus 172
  173. 173. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git 173
  174. 174. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git • Kubernetes ConfigMap 174
  175. 175. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git • Kubernetes ConfigMap • Redis 175
  176. 176. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git • Kubernetes ConfigMap • Redis • Zookeeper / Consul 176
  177. 177. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git • Kubernetes ConfigMap • Redis • Zookeeper / Consul • Vault 177
  178. 178. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git • Kubernetes ConfigMap • Redis • Zookeeper / Consul • Vault • Spring Config Server 178
  179. 179. • Formats • Properties • JSON • YAML • etc. Config • Sources • File / Directory • Environment Variables • System Properties • HTTP • Event Bus • Git • Kubernetes ConfigMap • Redis • Zookeeper / Consul • Vault • Spring Config Server • etc. 179
  180. 180. Data Access SQL & NoSQL
  181. 181. Out of the box • SQL • JDBC • MySQL • PostgreSQL Data Access 181
  182. 182. Out of the box • SQL • JDBC • MySQL • PostgreSQL • NoSQL • MongoDB • Redis Data Access 182
  183. 183. Out of the box • SQL • JDBC • MySQL • PostgreSQL • NoSQL • MongoDB • Redis 3rd party • Anything... Data Access 183
  184. 184. Integration
  185. 185. 185Integration • Event Bus Bridges • TCP Bridge
  186. 186. 186Integration • Event Bus Bridges • TCP Bridge • Camel Bridge
  187. 187. 187Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge
  188. 188. 188Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client
  189. 189. 189Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client • Kafka Client
  190. 190. 190Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client • Kafka Client • STOMP Server & Client
  191. 191. 191Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client • Kafka Client • STOMP Server & Client • IoT • MQTT
  192. 192. 192Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client • Kafka Client • STOMP Server & Client • IoT • MQTT • Java EE • JCA Resource Adaptor
  193. 193. 193Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client • Kafka Client • STOMP Server & Client • IoT • MQTT • Java EE • JCA Resource Adaptor • Misc • Mail Client
  194. 194. 194Integration • Event Bus Bridges • TCP Bridge • Camel Bridge • AMQP Bridge • Messaging & Streaming • RabbitMQ Client • Kafka Client • STOMP Server & Client • IoT • MQTT • Java EE • JCA Resource Adaptor • Misc • Mail Client • Consul Client
  195. 195. Metrics
  196. 196. Metrics 196 Micrometer
  197. 197. Metrics 197 Micrometer SignalFx StatsD New Relix Influx/Telegraf JMXPrometheus Netflix Atlas CloudWatch Datadog Graphite Ganglia Wavefront
  198. 198. Micrometer Dropwizard Health Check API Metrics 198
  199. 199. Reactive
  200. 200. fileSystem .rxReadFile("cities.txt").toFlowable() .flatMap(buffer -> Flowable.fromArray(buffer.toString().split("r?n"))) .flatMap(city -> searchByCityName(httpClient, city)) .flatMap(HttpClientResponse::toFlowable) .map(extractingWoeid()) .flatMap(cityId -> getDataByPlaceId(httpClient, cityId)) .flatMap(toBufferFlowable()) .map(Buffer::toJsonObject) .map(toCityAndDayLength()) .subscribe(System.out::println, Throwable::printStackTrace); Reactive Programming 200
  201. 201. Observable<Double> observable = vertx.eventBus(). <Double>consumer("heat-sensor"). bodyStream(). toObservable(); observable. buffer(1, TimeUnit.SECONDS). map(samples -> samples. stream(). collect(Collectors.averagingDouble(d -> d))). subscribe(heat -> { vertx.eventBus().send("news-feed", "Current heat is " + heat); }); Reactive Programming 201
  202. 202. • Vert.x supports • RxJava 1 Reactive Programming 202
  203. 203. • Vert.x supports • RxJava 1 • RxJava 2 Reactive Programming 203
  204. 204. • Vert.x supports • RxJava 1 • RxJava 2 • Reactive Streams (publishers & subscribers) Reactive Programming 204
  205. 205. Reactive Manifesto 205 Responsive Message Driven Elastic Resilient
  206. 206. Reactive & Distributed Vert.x Summary
  207. 207. Reactive & Distributed Event Bus 207
  208. 208. Reactive & Distributed Event Bus 208
  209. 209. Reactive & Distributed Event Bus Server 1 Server 2 Server 3 Server N... 209
  210. 210. Reactive & Distributed Event Bus Handler Handler Handler Handler Handler Handler Server 1 Server 2 Server 3 Server N... 210
  211. 211. Reactive & Distributed Module ModuleModule Event Bus Handler Handler Handler Handler Handler Handler Server 1 Server 2 Server 3 Server N... 211
  212. 212. Reactive & Distributed 212 Bridged Apps Data Access Metrics External Apps IoT Devices etc. Module ModuleModule Event Bus Handler Handler Handler Handler Handler Handler Server 1 Server 2 Server 3 Server N...
  213. 213. Reactive & Distributed 213 Bridged Apps Data Access Metrics External Apps IoT Devices etc. Module ModuleModule Event Bus Handler Handler Handler Handler Handler Handler Server 1 Server 2 Server 3 Server N...
  214. 214. • Java • JavaScript • Groovy • Ruby • Ceylon • Scala • Kotlin Polyglot 214 Bridged Apps Data Access Metrics External Apps IoT Devices etc. Module ModuleModule Event Bus Handler Handler Handler Handler Handler Handler Server 1 Server 2 Server 3 Server N...
  215. 215. • JavaScript • Vert.x event bus integration over SockJS for browser-based/node.js apps. Polyglot 215 Bridged Apps Data Access Metrics External Apps IoT Devices etc. Module ModuleModule Event Bus Handler Handler Handler Handler Handler Handler Server 1 Server 2 Server 3 Server N...
  216. 216. 216Reactive & Distributed Module Module Module Module Module Module Module Module Discovery & Configuration Distributed Application JDBC Client JDBC ? ? ? HTTP? ? Event Bus External Apps Polyglot Cloud IoT
  217. 217. Thank You! http://orkhan.io http://fb.com/groups/reactive.distributed

×