Proof of technology (POT) to evaluate Kotlin as the implementation language for Lagom microservices. Hello Lagom project (1.4.9) from Get Started with Lightbend Technologies was ported from Java to Kotlin (1.3.11) with 1 to 1 matching functionality.
Show Kotlin can be used for Lagom microservices to gain the productivity and language advancements compared to Java. Why not Scala? Scala would have been the logical choice and a good one, but I've found less resistance from team members to learn Kotlin compared to Scala.
- Maven POMs to include Kotlin dependencies
- Kotlin equivalent classes in src/kotlin and equivalent Java classes removed from src/java
- Lagom service interfaces ported to Kotlin caused this runtime error:
Caused by: java.lang.IllegalArgumentException: Service.descriptor must be implemented as a default method
Workaround explained here lagom/lagom#1180.
mvn lagom:runAll
- Get the hello resource for World
curl http://localhost:9000/api/hello/World
Default response will be
Hello, World!
- Change the hello resource
curl -H "Content-Type: application/json" -X POST -d '{"message": "Hi"}' http://localhost:9000/api/hello/World
Response will be
Hi, World!
- Run the integration test with lagom running, integration-tests/src/test/kotlin/.../StreamIT, to assert streaming works.
Lightbend's 'Hello Lagom' Java/Maven project was successfully ported to Kotlin. Unit and integration tests pass and the services are runnable. Hope this gives confidence for other developers to try Kotlin with Lagom.