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

Kotlin EE: Boost your Productivity @ KotlinConf...

Marcus Fihlon
November 03, 2017

Kotlin EE: Boost your Productivity @ KotlinConf 2017

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

November 03, 2017
Tweet

More Decks by Marcus Fihlon

Other Decks in Technology

Transcript

  1. 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)
  2. fun main(args: Array<String>): Unit = runBlocking { val jobs =

    List(10) { async(CommonPool) { PriceService().price } } println(jobs.sumBy { it.await() } / 10) }
  3. val page = html { head { title { "My

    Website" } } body { p { "Hello KotlinConf!" } } }
  4. • • • • • • • • • •

    • • • • dependencies { providedCompile "javax:javaee-api:$javaee_version" }
  5. • 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
  6. • 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/
  7. • docker swarm join-token worker • docker-machine ssh node01 •

    docker swarm join --token <token> 192.168.99.100:2377
  8. • docker-machine ssh mgr • docker service create --network kotlinconf

    \ --name timeservice mcpringle/timeservice • docker service create --network kotlinconf -p 8181:8080 \ --name helloservice mcpringle/helloservice • docker service ls
  9. • http http://192.168.99.100:8181/api/hello/kotlinconf • docker service update --replicas 3 helloservice

    • docker node update --availability drain mgr • docker node update --availability active mgr