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

Démystifier le réactif et l'orchestration de services avec Vert.x, Kubernetes et Kotlin

Démystifier le réactif et l'orchestration de services avec Vert.x, Kubernetes et Kotlin

Julien Ponge

March 29, 2018
Tweet

More Decks by Julien Ponge

Other Decks in Programming

Transcript

  1. Démystifier le réactif et l'orchestration de
    services avec Vert.x, Kubernetes et Kotlin

    View Slide

  2. Julien Ponge
    Maitre de Conférences
    “Delegated consultant to Red Hat” on Vert.x
    Eclipse Golo + extensive F/OSS background
    ! https://julien.ponge.org/
    " @jponge
    # @jponge
     https://www.mixcloud.com/hclcast/

    View Slide

  3. “No to average expertise on
    any of these technologies”
    ! "
    (or async)

    View Slide

  4. Kotlin?
    (1 slide to be an expert)

    View Slide

  5. data class Person(val name: String, val age: Int)
    fun String.yo() {
    println("$this -> Yo!")
    }
    fun wrap(block: () -> Unit) {
    println("{{{")
    block()
    println("}}}")
    }
    fun main(args: Array) {
    wrap {
    val phil = Person(name="Philippe", age=45)
    println(phil)
    phil.name.yo()
    }
    }

    View Slide

  6. data class Person(val name: String, val age: Int)
    fun String.yo() {
    println("$this -> Yo!")
    }
    fun wrap(block: () -> Unit) {
    println("{{{")
    block()
    println("}}}")
    }
    fun main(args: Array) {
    wrap {
    val phil = Person(name="Philippe", age=45)
    println(phil)
    phil.name.yo()
    }
    }

    View Slide

  7. data class Person(val name: String, val age: Int)
    fun String.yo() {
    println("$this -> Yo!")
    }
    fun wrap(block: () -> Unit) {
    println("{{{")
    block()
    println("}}}")
    }
    fun main(args: Array) {
    wrap {
    val phil = Person(name="Philippe", age=45)
    println(phil)
    phil.name.yo()
    }
    }

    View Slide

  8. data class Person(val name: String, val age: Int)
    fun String.yo() {
    println("$this -> Yo!")
    }
    fun wrap(block: () -> Unit) {
    println("{{{")
    block()
    println("}}}")
    }
    fun main(args: Array) {
    wrap {
    val phil = Person(name="Philippe", age=45)
    println(phil)
    phil.name.yo()
    }
    }
    {{{
    Person(name=Philippe, age=45)
    Philippe -> Yo!
    }}}

    View Slide

  9. Reactive?
    (because resources are scarce)

    View Slide

  10. View Slide

  11. Application

    View Slide

  12. 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 Slide

  13. 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 Slide

  14. x 1000 =
    %

    View Slide

  15. Virtual machines,
    Containers, etc

    View Slide

  16. View Slide

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

    View Slide

  18. 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 Slide

  19. (
    )
    (
    Http server verticle Database client verticle

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

    View Slide

  20. Events
    Thread
    Event Loop

    View Slide


  21. Verticles
    (
    (
    (
    public class SomeVerticle extends AbstractVerticle {
    @Override
    public void start() throws Exception { }
    @Override
    public void stop() throws Exception { }
    }
    class SomeVerticle : AbstractVerticle() {
    override fun start() { }
    override fun stop() { }
    }
    exports.vertxStart = function() { }
    exports.vertxStop = function() { }

    View Slide

  22. (demo)
    Hello Kotlin + Vert.x

    View Slide

  23. View Slide

  24. Async is hard

    (callback hell is just one facet)

    View Slide

  25. Kotlin coroutines
    Looks “like” sequential operations
    async/await, Go-style channels

    View Slide

  26. View Slide

  27. RxJava2 + Kotlin extensions
    Declarative data flows over event sources
    Operators transforming data + event streams

    View Slide

  28. fun main(args: Array) {
    val rand = Random()
    val o1 = Observable
    .fromCallable(rand ::nextInt)
    .repeat()
    .take(500, TimeUnit.MILLISECONDS)
    .filter { it > 0 }
    .filter { it % 2 == 0 }
    .map { "[${it}]" }
    val o2 = Observable.fromIterable(1 ..Long.MAX_VALUE)
    Observables
    .zip(o1, o2) { n, id -> "${id} -> ${n}" }
    .subscribeBy(
    onNext = logger ::info,
    onError = { logger.error("Oh?") },
    onComplete = { logger.info("Done!") }
    )
    }
    “id -> [n]”
    zip()

    View Slide

  29. Kubernetes?
    (orchestrating containers for you)

    View Slide

  30. https://cloud.google.com/kubernetes-engine/kubernetes-comic

    View Slide

  31. View Slide

  32. https://cloud.google.com/kubernetes-engine/kubernetes-comic

    View Slide

  33. https://cloud.google.com/kubernetes-engine/kubernetes-comic

    View Slide

  34. Pod
    Pod
    Pod
    Pod
    Pod
    Pod
    Pod Pod
    Node
    Node
    Master(s)

    View Slide

  35. Same host
    Same network
    Same namespace
    Same volumes
    Same secrets
    Pod
    Container
    Container
    Container

    View Slide

  36. Container
    Container
    Container
    Pod replicas & scaling
    Readiness probes
    Liveness probes
    Restart policy
    Rolling upgrades
    (…)

    View Slide

  37. Using Kubernetes
    (minikube is your friend)

    View Slide






  38. Temperatures services
    Aggregate Alarm

    View Slide


  39. Vert.x callbacks
    Coroutines, liveness
    RxKotlin
    Discovery
    RxKotlin, SockJS event bus bridge, VueJS, MongoDB

    View Slide

  40. (demo)
    Kubernetes (minikube)
    https://github.com/jponge/demo-vertx-kotlin-rxjava2-kubernetes

    View Slide

  41. Outro
    (how was the nap?)

    View Slide

  42. 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 Slide

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

    View Slide

  44. Q&A
    ! https://julien.ponge.org/
    " @jponge
    # @jponge
     https://www.mixcloud.com/hclcast/

    View Slide