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

Microservices with Micronaut - practical approach

Microservices with Micronaut - practical approach

1. Micronaut - what’s is it?
2. Reflection based vs compile time based approach to DI/AOP
3. Simplified Insurance Sales System - intro
4. Implementation examples

B30c151ccb4d043a2028691515db4130?s=128

Robert Witkowski

June 18, 2019
Tweet

Transcript

  1. Microservices with Micronaut - practical approach Robert Witkowski, Lead Software

    Engineer @rwitkowski_asc
  2. Agenda 1. Micronaut - what’s is it? 2. Reflection based

    vs compile time based approach to DI/AOP 3. Simplified Insurance Sales System - intro 4. Implementation examples 5. DEMO - Micronaut & GraalVM 6. DEMO - performance tests (startup, memory)
  3. http://micronaut.io/ A modern, JVM-based, full-stack framework for building modular, easily

    testable microservice and serverless applications.
  4. http://micronaut.io/ Designed from the ground-up for Microservices and Serverless Computing.

  5. http://micronaut.io/

  6. Micronaut features • lightweight and reactive • supports Java, Kotlin,

    Groovy • supports Maven/Gradle as build tools • built by the people that made Grails (over 10 years exp) • designed with microservices and cloud computing in mind with a lot of cloud-native features like: – service discovery – distributed tracing – asynchronous communication – retriable HTTP clients – circuit breakers – scalability and load balancing – external configuration
  7. https://www.thoughtworks.com/radar/languages-and-frameworks ThoughtWorks Technology Radar

  8. https://www.thoughtworks.com/radar/languages-and-frameworks ThoughtWorks Technology Radar The Assess ring are things to

    look at closely, but not necessarily trial yet - unless you think they would be a particularly good fit for you. Typically, blips in the Assess ring are things that we think are interesting and worth keeping an eye on.
  9. • No common reflection cache in Java, each library/framework produces

    a unique reflection cache. This makes it extremely difficult to optimize memory consumption. • Reflective calls are much more difficult for the JIT to optimize. • Traditional AOP is the heavy reliance on runtime proxy creation which slows app performance, makes debugging harder and increases memory consumption. https://stackoverflow.com/questions/435553/java-reflection-performance Reflection based approach to DI/AOP
  10. Reflection is powerful, but should not be used indiscriminately. If

    it is possible to perform an operation without using reflection, then it is preferable to avoid using it. Because reflection involves types that are dynamically resolved, certain JVM optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications. https://docs.oracle.com/javase/tutorial/reflect/index.html Trail: Reflection API
  11. • Processes classes at compile time and produces all metadata

    at compile time. • Doesn’t need to scan all your classes, methods, properties to “understand” your app. • Uses Ahead of Time (AOT) compilation via annotation processors or AST transforms for Groovy. Micronaut compile-time approach to DI/AOP
  12. • improves startup performance • reduces memory consumption • reducing

    proxies and stack trace sizes • improving debugging Micronaut compile-time approach to DI/AOP
  13. https://github.com/asc-lab/micronaut-microservices-poc Sample Project: Simplified Insurance Sales Portal

  14. pom.xml application.yml Accessing Relational Database with Hibernate

  15. Accessing Relational Database with Hibernate

  16. Accessing Relational Database with Micronaut Data Micronaut Data is a

    database access toolkit that uses Ahead of Time (AoT) compilation to pre-compute queries for repository interfaces that are then executed by a thin, lightweight runtime layer. • no runtime model • no query translation • no reflection or runtime proxy • type safety https://micronaut-projects.github.io/micronaut-data/latest/guide/
  17. Accessing Relational Database with Micronaut Data

  18. Mock Database for Testing

  19. pom.xml application.yml Accessing MongoDB

  20. Accessing MongoDB

  21. pom.xml application.yml Talking to Other Services using Kafka

  22. Talking to Other Services using Kafka - publish event

  23. Talking to Other Services using Kafka - subscribe event

  24. Talking to Other Services using RabbitMQ pom.xml application.yml

  25. Talking to Other Services using RabbitMQ - publish event

  26. Talking to Other Services using RabbitMQ - subscribe event

  27. Exposing REST Endpoints

  28. Talking to Other Services with HTTP

  29. Talking to Other Services with HTTP

  30. Test Your HTTP Endpoints

  31. Test Your HTTP Endpoints

  32. Service Discovery with Consul pom.xml application.yml

  33. Client-Side Load Balancing with Ribbon pom.xml application.yml

  34. Securing Services with JWT pom.xml application.yml

  35. Securing Services with JWT - auth provider

  36. Running Scheduled Tasks

  37. Tracing with Zipkin pom.xml application.yml

  38. Management and Monitoring pom.xml application.yml

  39. What’s else? • Micronaut AWS • Micronaut gRPC • Micronaut

    Flyway • Micronaut Liquibase • Micronaut GraphQL • Micronaut ElasticSearch • Micronaut Redis • Micronaut Neo4j • ....
  40. Deployment • docker-compose – localhost only – consul-based service-discovery •

    kubernetes – local & cloud – dns-based service-discovery
  41. GraalVM GraalVM is a universal virtual machine for running applications

    written in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Kotlin, Clojure, and LLVM-based languages such as C and C++.
  42. DEMO