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

Kotlin EE: Boost your Productivity @ JUG.CH Luzern 2018

Kotlin EE: Boost your Productivity @ JUG.CH Luzern 2018

Kotlin is a language for the JVM, invented by JetBrains a few years ago. But what the hell is Kotlin EE? If you never heard of Kotlin EE, don’t panic, it does not exist. But you can use it right away and boost your productivity!

I invented the term Kotlin EE as a synonym for using the Kotlin language together with the Java EE API to create services of any size (microservices, nanoservices etc.) with just a few lines of code and the ability to focus on the business logic.

Kotlin and Java EE are a perfect couple for writing micro- or nanoservices. Kotlin is a very pragmatic language, builds on many concepts and techniques from Java, designed for developer productivity. Kotlin works great with all existing Java libraries and frameworks and runs with the same level of performance as Java.

The Java EE API allows us to code against a proven and stable API. Provided libraries like JAX-RS for writing RESTful APIs and Jackson for JSON (de)serializing decrease the need for additional third-party libraries which results in a short build time and a small artifact size. Benefit from a very fast build and test feedback and stay focused on your code.

In this talk, I try to prove my statements from above. Live on stage I write a service in Kotlin with a RESTful JSON API with only a few lines of code and run the service using a local Docker cloud where you can see how these can be scaled up and down to manage fluctuating loads. Coding, building, testing, deploying, scaling: fast and efficient!

Marcus Fihlon

February 28, 2018
Tweet

More Decks by Marcus Fihlon

Other Decks in Technology

Transcript

  1. February 28, 2018
    Luzern

    View Slide







  2. View Slide

  3. View Slide

  4. View Slide







  5. View Slide

  6. View Slide






  7. View Slide

  8. View Slide









  9. View Slide

  10. fun main(args: Array) {
    val event = "KotlinConf"
    println("Hi $event!")
    }

    View Slide

  11. class Person(val name: String,
    val age: Int,
    val company: String?) {

    }

    View Slide

  12. open class Person(val name: String,
    val age: Int,
    val company: String?) {

    }

    View Slide

  13. data class Person(val name: String,
    val age: Int,
    val company: String?)
    val marcus = Person("Marcus", 29, null)
    println(marcus) // Person(name=Marcus, age=43, company=null)
    val marcusCSS = marcus.copy(company = "CSS Insurance")
    println(marcusCSS) // Person(name=Marcus, age=43, company=CSS Insurance)

    View Slide

  14. object PersonController {
    val persons = mutableListOf()
    fun save(person: Person) {
    persons.add(person)
    }

    }

    View Slide

  15. fun main(args: Array): Unit = runBlocking {
    val jobs = List(10) {
    async(CommonPool) {
    PriceService().price
    }
    }
    println(jobs.sumBy { it.await() } / 10)
    }

    View Slide

  16. val page = html {
    head {
    title { "My Website" }
    }
    body {
    p { "Hello KotlinConf!" }
    }
    }

    View Slide

  17. View Slide















  18. dependencies {
    providedCompile "javax:javaee-api:$javaee_version"
    }

    View Slide

  19. FROM payara/micro
    COPY myapplication.war /opt/payara/deployments

    View Slide

  20. View Slide

  21. View Slide

  22. buildscript {
    dependencies {
    classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
    }
    }
    allOpen {
    annotation('javax.ejb.Stateless')
    annotation('javax.ws.rs.Path')
    }

    View Slide

  23. buildscript {
    dependencies {
    classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
    }
    }
    noArg {
    annotation('javax.ws.rs.Path')
    }

    View Slide

  24. View Slide

  25. View Slide


  26. docker-machine ls

    docker-machine create -d virtualbox mgr

    docker-machine create -d virtualbox node01

    docker-machine ssh mgr

    docker swarm init --advertise-addr 192.168.99.100

    View Slide


  27. docker run -it -d -p 8080:8080 -e HOST=192.168.99.100 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --name visualizer dockersamples/visualizer

    http://192.168.99.100:8080/

    View Slide


  28. docker swarm join-token worker

    docker-machine ssh node01

    docker swarm join --token 192.168.99.100:2377

    View Slide


  29. docker-machine ssh mgr

    docker node ls

    docker info

    View Slide


  30. docker-machine ssh mgr

    docker network create -d overlay jugnet

    docker network ls

    View Slide


  31. docker-machine ssh mgr

    docker service create --network jugnet \
    --name timeservice mcpringle/timeservice

    docker service create --network jugnet -p 8181:8080 \
    --name helloservice mcpringle/helloservice

    docker service ls

    View Slide


  32. http http://192.168.99.100:8181/api/hello/jug

    docker service update --replicas 3 helloservice

    docker node update --availability drain mgr

    docker node update --availability active mgr

    View Slide

  33. View Slide





  34. View Slide

  35. View Slide















  36. View Slide

  37. View Slide