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

50a17cd98aab2cc4d8e144741e11b1b7?s=128

Julien Ponge

April 19, 2018
Tweet

Transcript

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

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

  3. “No to average expertise on any of these technologies” !

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

  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<String>) { wrap { val phil = Person(name=“Philippe C”, age=49) println(phil) phil.name.yo() } }
  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<String>) { wrap { val phil = Person(name=“Philippe C”, age=49) println(phil) phil.name.yo() } }
  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<String>) { wrap { val phil = Person(name=“Philippe C”, age=49) println(phil) phil.name.yo() } }
  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<String>) { wrap { val phil = Person(name=“Philippe C”, age=49) println(phil) phil.name.yo() } } {{{ Person(name=Philippe C, age=49) Philippe -> Yo! }}}
  9. Reactive? (because resources are scarce)

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

  12. 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"); } }
  13. x 1000 = %

  14. Virtual machines, Containers, etc

  15. None
  16. Vert.x? (async all the things!)

  17. 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
  18. ( ) ( Http server verticle Database client verticle 

    Event Bus + ) “Details for user 1234?” “{data}” 4 instances 1 instance
  19. Events Thread Event Loop ( ( ( ( (

  20. (demo) Hello Kotlin + Vert.x

  21. None
  22. Async is hard (callback hell is just one facet)

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

    1/2
  24. None
  25. None
  26. RxJava2 + Kotlin extensions Declarative data flows over event sources

    Operators transforming data + event streams 2/2
  27. fun main(args: Array<String>) { 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!") } ) }
  28. fun main(args: Array<String>) { 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!") } ) }
  29. fun main(args: Array<String>) { 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()
  30. Kubernetes? (orchestrating containers for you)

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

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

  34. Pod Pod Pod Pod Pod Pod Pod Pod Node Node

    Master(s)
  35. Same host Same network Same namespace Same volumes Same secrets

    Pod Container Container Container
  36. Container Container Container Pod replicas & scaling Readiness probes Liveness

    probes Restart policy Rolling upgrades (…)
  37. Using Kubernetes (minikube is your friend)

  38. ⚙ Temperatures services Aggregate Alarm

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

  40. Outro (how was the nap?)

  41. 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)
  42. 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
  43. Lunch at your company?

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