Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive programming on the JVM fast and produc...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Reactive programming on the JVM fast and productive

Paulo Lopes

December 14, 2016

Transcript

47 slides
  1. UNOPINIONATED import io.vertx.core.AbstractVerticle; public class Server extends AbstractVerticle { public

    void start() { vertx.createHttpServer().requestHandler(req -> { req.response() .putHeader("content-type", "text/plain") .end("Hello from Vert.x!"); }).listen(8080); } }
  2. REACTIVE conn.query("SELECT * from EMP", res -> { if (res.succeeded())

    { // Get the result set ResultSet resultSet = res.result(); } else { // Failed! } });
  3. C10K SERVER app .route("/eventbus/*") .handler(SockJSHandler.create(vertx).bridge(options)); vertx .createHttpServer() .requestHandler(app::accept) .listen(8080, res

    -> { // publish a new message every 10 sec vertx.setPeriodic(10000L, t -> { vertx.eventBus().publish("time", new JsonObject() .put("unixtime", System.currentTimeMillis())); }); System.out.println("Server ready!"); });
  4. C10K CLIENT for (int i = 0; i < sockets.length;

    i++) { vertx .createHttpClient() .websocket(8080, "localhost", "/eventbus/websocket", ws -> { ws.frameHandler(frame -> println(frame.binaryData())); // subscribe to the "time" address ws.writeFrame(WebSocketFrame.textFrame(SUBSCRIBE, true)); }); }

More Decks by Paulo Lopes

Other Decks in Programming