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

At MiXiT 2018

Julien Ponge

April 19, 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 full-size slide

  2. ! https://julien.ponge.org/
    " @jponge
    # @jponge
     https://www.mixcloud.com/hclcast/

    View full-size slide

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

    View full-size slide

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

    View full-size 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 C”, age=49)
    println(phil)
    phil.name.yo()
    }
    }

    View full-size 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 C”, age=49)
    println(phil)
    phil.name.yo()
    }
    }

    View full-size 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 C”, age=49)
    println(phil)
    phil.name.yo()
    }
    }

    View full-size 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 C”, age=49)
    println(phil)
    phil.name.yo()
    }
    }
    {{{
    Person(name=Philippe C, age=49)
    Philippe -> Yo!
    }}}

    View full-size slide

  9. Reactive?
    (because resources are scarce)

    View full-size slide

  10. 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

  11. 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

  12. Virtual machines,
    Containers, etc

    View full-size slide

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

    View full-size slide

  14. 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

  15. (
    )
    (
    Http server verticle Database client verticle

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

    View full-size slide

  16. Events
    Thread
    Event Loop
    (
    (
    (
    (
    (

    View full-size slide

  17. (demo)
    Hello Kotlin + Vert.x

    View full-size slide

  18. Async is hard

    (callback hell is just one facet)

    View full-size slide

  19. Kotlin coroutines
    Looks “like” sequential operations
    async/await + Go-style channels
    1/2

    View full-size slide

  20. RxJava2 + Kotlin extensions
    Declarative data flows over event sources
    Operators transforming data + event streams
    2/2

    View full-size slide

  21. 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!") }
    )
    }

    View full-size slide

  22. 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!") }
    )
    }

    View full-size slide

  23. 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 full-size slide

  24. Kubernetes?
    (orchestrating containers for you)

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. Pod
    Pod
    Pod
    Pod
    Pod
    Pod
    Pod Pod
    Node
    Node
    Master(s)

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  30. Using Kubernetes
    (minikube is your friend)

    View full-size slide






  31. Temperatures services
    Aggregate Alarm

    View full-size slide

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

    View full-size slide

  33. Outro
    (how was the nap?)

    View full-size slide

  34. 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

  35. 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 full-size slide

  36. Lunch at your
    company?

    View full-size slide

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

    View full-size slide