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

Vert.x Montreal JUG 2018

Vert.x Montreal JUG 2018

Julien Ponge

October 25, 2018
Tweet

More Decks by Julien Ponge

Other Decks in Programming

Transcript

  1. Julien Ponge Thomas Segismont
    @jponge @tsegismont

    View full-size slide

  2. Shameless plug

    View full-size slide

  3. Reactive?
    (because resources are scarce)

    View full-size slide

  4. Reactive
    systems
    Reactive
    streams
    Reactive
    programming
    Reactive
    “Responding to stimuli”
    Manifesto, Actor, Messages
    Resilience, Elasticity, Scalability,
    Asynchronous, non-blocking
    Data flow
    Back-pressure
    Non-blocking
    Data flow
    Events, Observable
    Spreadsheets
    Akka, Vert.x Akka Streams, RxJava,
    Reactor, Vert.x
    Reactor, Reactive Spring,
    RxJava, Vert.x

    View full-size slide

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

    View full-size slide

  6. Virtual machines,
    Containers, etc

    View full-size slide

  7. Vert.x?
    (async all the things!)

    View full-size slide

  8. Eclipse Vert.x
    Open source project started in 2012
    Eclipse / Apache licensing
    A toolkit for building reactive applications for the JVM
    7K ⋆ on #
    Built on top of
    $ https://vertx.io
    % @vertx_project

    View full-size slide

  9. &
    '
    &
    Http server verticle Database client verticle

    Event Bus
    )
    '
    “Details for user 1234?”
    “{data}”
    4 instances
    1 instance

    View full-size slide

  10. Events
    Thread
    Event Loop
    &
    &
    &
    &
    &

    View full-size slide

  11. (demo)
    Hello Vert.x

    View full-size slide

  12. foo.a(1, res1 -> {
    if (res1.succeeded()) {
    bar.b("abc", 1, res2 -> {
    if (res.succeeded()) {
    baz.c(res3 -> {
    dosomething(res1, res2, res3, res4 -> {
    // (...)
    });
    });
    }
    });
    }
    });
    “Callback hell”

    View full-size slide

  13. Callbacks RxJava 1 + 2
    Quasar (vertx-sync)
    Kotlin coroutines
    (core)
    (codegen)

    View full-size slide

  14. Boiler Vroom
    (in the mix)

    View full-size slide

  15. *
    )
    WebMidi
    JSON / Event Bus

    View full-size slide

  16. const eventBus = new EventBus("/eventbus")
    traktorIn.addListener("controlchange", 5, (event) => {
    eventBus.publish("boilervroom.vu-meter", {
    type: "volume-level",
    value: event.value
    })
    })
    eventBus.publish("boilervroom.fromtraktor", {
    type: "filter",
    number: 1,
    value: (event.value !== 0)
    })
    Event Bus

    View full-size slide

  17. +
    ,
    -
    .
    IceCast
    VLC
    * Chrome / DJ Booth app Clients
    /
    NuProcess
    MIDI
    Event Bus
    Event Bus

    View full-size slide

  18. SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    PermittedOptions permittedOptions = new PermittedOptions()
    .setAddressRegex(“boilervroom\\ ..+”);
    BridgeOptions bridgeOptions = new BridgeOptions()
    .addInboundPermitted(permittedOptions)
    .addOutboundPermitted(permittedOptions);
    sockJSHandler.bridge(bridgeOptions);
    router.route("/eventbus /*").handler(sockJSHandler);

    View full-size slide

  19. +
    ,
    -
    .
    IceCast
    VLC
    Clients
    /
    OGG/Vorbis
    OGG/Vorbis
    MP3
    MP3
    HTTP 1.0
    HTTP 1.1
    HTTP Client Event bus → Chunked HTTP

    View full-size slide

  20. router.get("/audiostream").handler(context -> {
    HttpServerResponse response = context.response();
    response.setStatusCode(200);
    response.setChunked(true);
    response.putHeader("Content-Type", "audio/mpeg");
    MessageConsumer consumer = eventBus.consumer("boilervroom.audiostream");
    consumer.bodyStream().handler(buffer -> {
    if (!response.writeQueueFull()) {
    response.write(buffer);
    }
    });
    response.endHandler(v -> {
    consumer.unregister();
    });
    response.exceptionHandler(t -> {
    consumer.unregister();
    });
    });

    View full-size slide

  21. Unified end-to-end reactive model + ecosystem
    (not just APIs…)
    For all kinds of distributed applications
    (even the small-scale ones)
    Flexible toolkit, not a framework
    (your needs, your call)

    View full-size slide

  22. https: //youtu.be/ZkWsilpiSqw
    0 Applications réactives avec Eclipse Vert.x
    1 Building Reactive Microservices in Java
    https: //goo.gl/ep6yB9
    1 Guide to async programming with Vert.x for Java developers
    https: //goo.gl/AcWW3A

    View full-size slide

  23. Q&A
    Use mlponge to get 50% off

    View full-size slide