SERVERLESS AND EVENT-DRIVEN MICROSERVICES WITH MICRONAUT
MICHAEL CARDUCCI@MICHAELCARDUCCI
AGENDA
• What is Micronaut• Why another framework?• The challenges of Microservices• Installation• The Micronaut CLI• Hello World Service• Inter-service Communication• RabbitMQ• Event-Driven Microservices• Writing and Deploying Serverless Functions
WHAT IS MICRONAUT?
”
“A MODERN, JVM-BASED, FULL-
STACK FRAMEWORK FOR BUILDING MODULAR, EASILY TESTABLE
MICROSERVICE APPLICATIONS. OCI
WHY (YET) ANOTHER FRAMEWORK?
GRAILS (CIRCA 2006)
THERE HAD TO BE A BETTER WAY
A LOT HAS CHANGED SINCE THEN
GRAILS THEN AND NOW
• Monoliths were the dominant pattern
• No major JS frameworks yet
• No Docker
• Cloud was very different
• …A lot can change in 12 years
• Microservices are becoming a dominant pattern
• The way we build web apps has completely changed
• The way we deploy apps has completely changed
• The framework evolves with the times
2006 2018
• Fast Startup Time• Reduced Memory Footprint• Minimal Use of Reflection• Minimal Use of Proxies• As small as possible JAR sizes• Zero Dependencies
• Fast Startup Time• Reduced Memory Footprint• Minimal Use of Reflection• Minimal Use of Proxies• As small as possible JAR sizes• Zero Dependencies
• Fast Startup Time• Reduced Memory Footprint• Minimal Use of Reflection• Minimal Use of Proxies• As small as possible JAR sizes• Zero Dependencies
THE RESULTS
• JAR files
• 8MB in Java
• 12 MB in Groovy
• Spring and Groovy – 36MB
• Grails – 27 MB
• Heap size
• 7MB in Java
• 19 MB in Groovy
• Spring and Groovy – 33 MB
• Grails – 49 MB
• Startup time
• Java ~1 second
• Spring / Grails ~3-4 seconds
HOW?
• Compile time dependency Injection & AOP for Groovy, Java and Kotlin
• AST Transforms for Groovy, Annotation processors for Java/Kotlin
• Annotation Metadata produced at compile Time
• Reflection Free and No Reflection Data Caching
SPRING (AND GRAILS) ARE EXPENSIVE
Read the bytecode
01Synthesize new annotations
02Build reflection metadata
03
SPRING (AND GRAILS) ARE EXPENSIVE
Read the bytecode
01Synthesize new annotations
02Build reflection metadata
03
THE CHALLENGE
• Spring (and grails) offer a productivity and a great programming model
• With Spring (and grails) non-trivial apps get bloated quickly
• There has to be a better way
• Designed from the ground up with microservices in mind
• Ultra-lightweight and reactive – Based on Netty• Integrated AOP and Compile-time DI• HTTP Client & Server
NATIVELY CLOUD NATIVE
• Service discovery / orchestration• Configuration• Immutable Deployments• Efficient service interaction• Elastic scaling• Cloud Awareness• Monitoring• Tracing• Security• Resilience (also degrading)• Cloud Functions
INSTALLING MICRONAUT
INSTALLING MICRONAUT
Download the Binariesmicronaut.io/download.html
Extract
Create MICRONAUT_HOME env var to point to extract location
Update PATH to include %MICRONAUT_HOME%/bin
INSTALLING MICRONAUT
INSTALLING MICRONAUT
LET’S DIVE IN…
EVENT DRIVEN MICROSERVICES
MICRONAUT + RABBITMQ
RabbitMQ is an open-source message-broker software that originally implemented the Advanced Message Queuing Protocol (AMQP) and has since been extended with a plug-in architecture to support Streaming Text Oriented Messaging Protocol (STOMP), Message Queuing Telemetry Transport (MQTT), and other protocols.git clone https://github.com/micronaut-guides/micronaut-rabbitmq.git
LET’S BUILD THIS
WRITING SERVERLESS FUNCTIONS
SUPPORTED INTERFACES
• Supplier
• Consumer
• BiConsumer
• Function
• BiFunction
CREATING A FUNCTION
FUNCTION BODY
FUNCTION CLIENT
FUNCTION CLIENT
FUNCTION CLIENT
MANUAL CONFIGURATION
ADD PROVIDER TO BUILD FILE
SET YOUR PROJECT’S MAIN CLAS
CONFIGURING FUNCTION TO EXECUTE –APPLICATION.YML
CONFIGURING FUNCTION TO EXECUTE - DOCKER
THANK YOU!MICHAEL CARDUCCI
ACKNOWLEDGEMENTS + RESOURCES
• Micronaut Guides - https://guides.micronaut.io/
• Ivan Lopez – RabbitMQ and Micronaut - https://guides.micronaut.io/micronaut-rabbitmq/guide/index.html
• Micronaut Docs - https://docs.micronaut.io/latest/guide/index.html#messaging
• What is a Reactive Microservice - https://www.oreilly.com/ideas/what-is-a-reactive-microservice