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

Démystifier le réactif et l'orchestration de se...

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. 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() } }
  2. 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() } }
  3. 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() } }
  4. 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! }}}
  5. 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
  6. 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"); } }
  7. 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
  8. ( ) ( Http server verticle Database client verticle 

    Event Bus + ) “Details for user 1234?” “{data}” 4 instances 1 instance
  9. RxJava2 + Kotlin extensions Declarative data flows over event sources

    Operators transforming data + event streams 2/2
  10. 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!") } ) }
  11. 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!") } ) }
  12. 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()
  13. 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)
  14. 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