Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Kotlin? (1 slide to be an expert)

Slide 5

Slide 5 text

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() } }

Slide 6

Slide 6 text

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() } }

Slide 7

Slide 7 text

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() } }

Slide 8

Slide 8 text

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! }}}

Slide 9

Slide 9 text

Reactive? (because resources are scarce)

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Application

Slide 12

Slide 12 text

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"); } }

Slide 13

Slide 13 text

x 1000 = %

Slide 14

Slide 14 text

Virtual machines, Containers, etc

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Vert.x? (async all the things!)

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

( ) ( Http server verticle Database client verticle  Event Bus + ) “Details for user 1234?” “{data}” 4 instances 1 instance

Slide 19

Slide 19 text

Events Thread Event Loop ( ( ( ( (

Slide 20

Slide 20 text

(demo) Hello Kotlin + Vert.x

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Async is hard (callback hell is just one facet)

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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()

Slide 30

Slide 30 text

Kubernetes? (orchestrating containers for you)

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Pod Pod Pod Pod Pod Pod Pod Pod Node Node Master(s)

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Using Kubernetes (minikube is your friend)

Slide 38

Slide 38 text

⚙ Temperatures services Aggregate Alarm

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Outro (how was the nap?)

Slide 41

Slide 41 text

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)

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Lunch at your company?

Slide 44

Slide 44 text

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