SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation...

46

Transcript of SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation...

Page 1: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •
Page 2: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

SERVERLESS AND EVENT-DRIVEN MICROSERVICES WITH MICRONAUT

MICHAEL CARDUCCI@MICHAELCARDUCCI

[email protected]

Page 3: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 4: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

WHAT IS MICRONAUT?

Page 5: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

“A MODERN, JVM-BASED, FULL-

STACK FRAMEWORK FOR BUILDING MODULAR, EASILY TESTABLE

MICROSERVICE APPLICATIONS. OCI

Page 6: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

WHY (YET) ANOTHER FRAMEWORK?

Page 7: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

GRAILS (CIRCA 2006)

Page 8: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

THERE HAD TO BE A BETTER WAY

Page 9: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

A LOT HAS CHANGED SINCE THEN

Page 10: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 11: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •
Page 12: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •
Page 13: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •
Page 14: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

• Fast Startup Time• Reduced Memory Footprint• Minimal Use of Reflection• Minimal Use of Proxies• As small as possible JAR sizes• Zero Dependencies

Page 15: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

• Fast Startup Time• Reduced Memory Footprint• Minimal Use of Reflection• Minimal Use of Proxies• As small as possible JAR sizes• Zero Dependencies

Page 16: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

• Fast Startup Time• Reduced Memory Footprint• Minimal Use of Reflection• Minimal Use of Proxies• As small as possible JAR sizes• Zero Dependencies

Page 17: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 18: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 19: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

SPRING (AND GRAILS) ARE EXPENSIVE

Read the bytecode

01Synthesize new annotations

02Build reflection metadata

03

Page 20: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

SPRING (AND GRAILS) ARE EXPENSIVE

Read the bytecode

01Synthesize new annotations

02Build reflection metadata

03

Page 21: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 22: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

• 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

Page 23: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

NATIVELY CLOUD NATIVE

• Service discovery / orchestration• Configuration• Immutable Deployments• Efficient service interaction• Elastic scaling• Cloud Awareness• Monitoring• Tracing• Security• Resilience (also degrading)• Cloud Functions

Page 24: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

INSTALLING MICRONAUT

Page 25: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 26: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

INSTALLING MICRONAUT

Page 27: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

INSTALLING MICRONAUT

Page 28: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

LET’S DIVE IN…

Page 29: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

EVENT DRIVEN MICROSERVICES

Page 30: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 31: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

LET’S BUILD THIS

Page 32: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

WRITING SERVERLESS FUNCTIONS

Page 33: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

SUPPORTED INTERFACES

• Supplier

• Consumer

• BiConsumer

• Function

• BiFunction

Page 34: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

CREATING A FUNCTION

Page 35: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

FUNCTION BODY

Page 36: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

FUNCTION CLIENT

Page 37: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

FUNCTION CLIENT

Page 38: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

FUNCTION CLIENT

Page 39: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

MANUAL CONFIGURATION

Page 40: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

ADD PROVIDER TO BUILD FILE

Page 41: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

SET YOUR PROJECT’S MAIN CLAS

Page 42: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

CONFIGURING FUNCTION TO EXECUTE –APPLICATION.YML

Page 43: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

CONFIGURING FUNCTION TO EXECUTE - DOCKER

Page 45: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •

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

Page 46: SERVERLESS AND EVENT-DRIVEN - DeveloperMarch...• The challenges of Microservices • Installation • The Micronaut CLI • Hello World Service • Inter-service Communication •