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

Kotlin EE: Boost your Productivity @ Voxxed Day...

Kotlin EE: Boost your Productivity @ Voxxed Days Vienna 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

March 12, 2018
Tweet

More Decks by Marcus Fihlon

Other Decks in Technology

Transcript

  1. @McPringle Disclaimer The following presentation has been approved for open

    audiences only. Hypersensitivity to occasional profanity requires covering ears. All logos, photos etc. used in this presentation are the property of their respective copyright owners and are used here for educational purposes only. Any and all marks used throughout this presentation are trademarks of their respective owners. The presenter is not acting on behalf of CSS Insurance, neither as an official agent nor representative. The views expressed are those solely of the presenter. Marcus Fihlon disclaims all responsibility for any loss or damage which any person may suffer from reliance on this information or any opinion, conclusion or recommendation in this presentation whether the loss or damage is caused by any fault or negligence on the part of presenter or otherwise.
  2. @McPringle About me • Software Engineer CSS Insurance, Open Source

    Software • Agile Coach CSS Insurance • Lecturer TEKO Swiss Technical College • Speaker Conferences, User Groups, Meetups • Author Articles, Books • Community Leader Hackergarten, Java User Group Switzerland, Kotlin Swiss User Group, Voxxed Days Zürich, BaselOne
  3. @McPringle Coming soon* Kotlin Web Development Develop full stack web

    applications with Kotlin and React.js Packt Publishing ISBN 978-1-78862-031-4 * around Q3/2018
  4. @McPringle About Kotlin • Statically typed • Object oriented •

    Java compatible • Easy to learn • Compiles to Java 6 Bytecode • Compiles to Java 8 Bytecode • Transpiles to JavaScript • Compiles to Native
  5. @McPringle Kotlin Syntax fun main(args: Array<String>) { val event =

    "Voxxed Days Vienna" println("Hi $event!") // Hi Voxxed Days Vienna! }
  6. @McPringle Data classes data class Person(val name: String, val age:

    Int, val company: String?) val marcus = Person("Marcus", 44, null) println(marcus) // Person(name=Marcus, age=44, company=null) val marcusCSS = marcus.copy(company = "CSS Insurance") println(marcusCSS) // Person(name=Marcus, age=44, company=CSS Insurance)
  7. @McPringle Default Values data class Person(val name: String, val age:

    Int, val company: String? = null) val marcus = Person("Marcus", 44) println(marcus) // Person(name=Marcus, age=44, company=null) val marcusCSS = Person("Marcus", 44, "CSS Insurance") println(marcusCSS) // Person(name=Marcus, age=44, company=CSS Insurance)
  8. @McPringle Named Parameters data class Person(val name: String, val age:

    Int, val company: String? = null) val marcus = Person(name = "Marcus", age = 44) println(marcus) // Person(name=Marcus, age=44, company=null) val marcusCSS = marcus.copy(company = "CSS Insurance") println(marcusCSS) // Person(name=Marcus, age=44, company=CSS Insurance)
  9. @McPringle String Templates data class Person(val name: String, val age:

    Int, val company: String? = null) val marcus = Person(name = "Marcus", age = 44) println("$marcus.name is $marcus.age years old") // Marcus is 44 years old println("${marcus}.name is $marcus.age years old") // Person(name=Marcus, age=44, company=null).name is 44 years old
  10. @McPringle Multiline Strings data class Person(val name: String, val age:

    Int, val company: String? = null) val marcus = Person(name = "Marcus", age = 44) println("""Name: $marcus.name Age: $marcus.age Company: $marcus.company""")
  11. @McPringle Coroutines fun main(args: Array<String>): Unit = runBlocking { val

    jobs = List(10) { async(CommonPool) { PriceService().price } } println(jobs.sumBy { it.await() } / 10) }
  12. @McPringle Typesafe Builder val page = html { head {

    title { "My Website" } } body { p { "Hello Voxxed Days Vienna!" } } }
  13. @McPringle Library Management as a Service • Servlets, JSTL, EL

    and JSPs • WebSockets • JSF • JAX-RS • EJB lite • JTA • JPA • Bean Validation • CDI • Interceptors • JBatch • Concurrency • JCache • … dependencies { providedCompile "javax:javaee-api:$javaee_version" }
  14. @McPringle Ready to use containers FROM payara/micro COPY myapplication.war /opt/payara/deployments

    My Application Application Server Java Runtime Operating System changes very infrequently changes sometimes, if not delayed changes frequently changes on every build
  15. @McPringle Classes final by default buildscript { dependencies { classpath

    "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" } } allOpen { annotation('javax.ejb.Stateless') annotation('javax.ws.rs.Path') }
  16. @McPringle Prepare the Swarm • List all available machines •

    Create a new machine to be used as a manager node • Create a new machine to be used as a worker node • Login to the manager • Initialize the swarm
  17. @McPringle • Start the visualizer service • Open the visualizer

    service in a web browser Prepare the Visualizer
  18. @McPringle Join the Swarm • Ask the manager node for

    the token to join the swarm • Login to the worker node • Join the worker to the swarm
  19. @McPringle Verify the Swarm • Login to the manager •

    List all nodes • Show more detailed information
  20. @McPringle Create a Network • Login to the manager •

    Create a new overlay network • List all networks
  21. @McPringle Deploy Services • Login to the manager • Deploy

    the time service • Deploy the hello service • List all services
  22. @McPringle Testing, Scaling and Maintenance • Testing our services •

    Scaling services up and down • Take a node out of service • Take a node back into service
  23. @McPringle Conclusion With Kotlin, Java EE and Docker you get:

    • Easy to understand code • Fast build times • Reproducible deployments • Easy scaling of your services You are fast and efficient because you have your focus on your business code. You create business value!
  24. @McPringle Code Warriors wanted! About you • You are frighteningly

    awesome at what you do. • You can perform quick and deadly tactical strikes, as well as feats of epic badassery. Sometimes both at the same time. • You would rather refactor existing, mostly working, ugly code instead of rewriting it from scratch. OK nobody would really rather do that, but you know it's the right and honorable thing to do most of the time. • You know where your towel is. About us • Biggest Basic Health Insurance Company • 2700 Employees • 300 IT Professionals • 24 Scrum Teams • 130 Software Developers • Flexible working times • Personal development support • 6 weeks paid vacation • Great benefits • Located in Lucerne, Switzerland Contact me: [email protected]