Groovy-Powered Microservices with Micronaut

Zachary Klein
Zachary KleinSoftware Engineer at Object Computing, Inc
objectcomputing.com
© 2022, Object Computing, Inc. (OCI). All rights reserved. No part of these notes may be reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior, written permission of Object Computing, Inc. (OCI)
Groovy-Powered Microservices
with Micronaut
Zachary Klein, Principal Software Engineer, 2GM Team
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ Zachary Klein - Developer & Architect
❖ Principal Software Engineer at Object
Computing, Inc
❖ 12+ years of software development experience
❖ OSS contributor
❖ Training instructor
2
About me
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
A modern, JVM-based, full-stack framework for building modular,
easily testable microservice and serverless applications.
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
https://micronaut.io/launch
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
❖ Controller with
Dependency Injection
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ Micronaut is language-agnostic
❖ 1st Class support for:
❖ Java
❖ Kotlin
❖ Groovy
6
Micronaut and Groovy
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ Micronaut implements core framework
components using Groovy language features
❖ E.g, Groovy AST transformations are used
for AOT compilation support (vs Annotation
Processors in Java/Kotlin)
❖ Support for Groovy configuration files,
serverless functions, Spock/Geb tests, and
GORM!
7
Micronaut and Groovy
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
❖ Controller with
Dependency Injection
❖ New class files generated
at compilation time (via
AST Transformations) to
implement the controller,
instantiate & supply
dependencies, etc
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
❖ Controller with
Dependency Injection
❖ New class files generated
at compilation time (via
AST Transformations) to
implement the controller,
instantiate & supply
dependencies, etc
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ Micronaut Launch is the recommended
method for creating Micronaut apps
❖ Choose Groovy as the Language (and
Spock as testing framework, if desired)
❖ Using the CLI:
10
Getting Started
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 11
Getting Started
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 12
Getting Started
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 13
Getting Started
Groovy auto-imports the
groovy.lang.singleton
annotation - make sure you
import from jakarta.inject
!
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
❖ Dependency Injection via
@Inject
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
❖ Micronaut’s HTTP Client
(implemented through
Groovy AST
Transformations)
Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved.
❖ Dependency Injection via
Constructor Injection
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ YAML is the default, but Groovy
is supported
❖ Groovy allows for powerful,
expressive, programmatic
configuration
❖ Can mix and match!
17
Configuration with Groovy
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 18
Configuration with Groovy
❖ Micronaut accepts
configuration in JSON,
properties, YAML, and
Groovy ConfigSlurper (also
env variables, system
properties)
❖ Note that properties cannot
contain dashes - use
camelCase or snake_case
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ Micronaut Controllers (and Clients) express routes
declaratively via annotation arguments:
❖ @Controller("/hello")
❖ @Get("/profile “)
❖ Optionally, routes can be expressed
programmatically using the RouteBuilder interface
❖ GroovyRouteBuilder provides an expressive DSL
for routes (similar to Grails UrlMappings)
19
Controller Routes
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 20
Controller Routes
❖ Annotation-based routes
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 21
Controller Routes
❖ GroovyRouteBuilder
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 22
@MicronautTest & Spock
❖ Micronaut is test-framework agnostic - no special
tooling required
❖ E.g, JUnit, Spock
❖ Because of Micronaut’s fast startup time, many
developers prefer integration tests
❖ @MicronautTest automatically starts up the
application context for the test run, and shuts it
down cleanly
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 23
@MicronautTest & Spock
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 24
@MicronautTest & Spock
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 25
@MicronautTest & Spock
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 26
@MicronautTest & Spock
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 27
@MicronautTest & Spock
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 28
Micronaut and GORM
❖ GORM is the persistence framework pioneered by
the Grails framework - https://gorm.grails.org
❖ GORM provides expressive querying, persistence
and domain modeling features, including
validation, multi-tenancy, and more
❖ When configured with Groovy support, Micronaut
apps can leverage GORM’s powerful features in a
comparatively lightweight manner
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 29
Micronaut and GORM
Dependency Description
micronaut-
hibernate-gorm
Configures GORM for Hibernate for Groovy
applications
micronaut-mongo-
gorm
Configures GORM for Mongo DB for Groovy
applications
micronaut-neo4j-
gorm
Configures GORM for Mongo DB for Groovy
applications
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 30
Adding GORM to Micronaut
❖ Using Micronaut Launch
or the CLI command
feature-diff, you can
generate a delta showing
how to add a feature, like
hibernate-gorm
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 31
Adding GORM to Micronaut
❖ Add GORM and JDBC
dependencies - also a
database driver (H2 in this
demo)
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
Configuring Datasources
❖ Datasource configuration
❖ Standard Hibernate/JDBC
configuration properties -
database credentials,
dialect, etc
❖ Can configure multiple
datasources
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
Enabling Entity-scanning
❖ Application class needs to
be modified
❖ Application context is
started up using the
builder pattern - the
packages() method
species the package under
which entities are defined
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 34
Creating Domain Classes (aka Entities)
❖ A Domain Class / Entity can
be a simple POGO
annotated with @Entity
❖ Class name will be mapped
as database table name (by
convention)
❖ Properties of the class will be
mapped to columns in the
database table
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 35
Creating Domain Classes (aka Entities)
❖ Additional data-mapping
features (like validation)
can be added by
implementing the
GormEntity<> trait
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 36
GORM Data Services in Micronaut
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 37
GORM Data Services in Micronaut
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 38
GORM Multi-tenancy
https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 39
GORM Multi-tenancy
https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 40
GORM Multi-tenancy
https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 41
GORM Multi-tenancy
https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 42
GORM Multi-tenancy Modes
https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
Modes Description Isolation
DATABASE
Separate database with a
separate connection pool is used
to store each tenants data.
HIGHEST
SCHEMA
The same database, but different
schemas are used to store each
tenants’ data.
HIGH
DISCRIMINATOR
The same database is used with
a discriminator used to partition
and isolate data.
LOW
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 43
GORM Multi-tenancy Tenant Resolvers
https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
Name Description
CookieTenantResolver Removes the current tenant from an HTTP cookie
FixedTenantResolver Resolves against a fixed tenant id
HttpHeaderTenantResolver Resolves the current tenant from the request HTTP Header
PrincipalTenantResolver Resolves the current tenant from the authenticated username
SessionTenantResolver Resolves the current tenant from the HTTP Session
SubdomainTenantResolver Resolves the tenant id from the subdomain
SystemPropertyTenantResolver Resolves the tenant id from a system property
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 44
GORM Multi-tenancy: Specify tenantId
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 45
GORM Multi-tenancy Transformations (Annotations)
Transformation Description
@CurrentTenant Resolve the current tenant for the context of a class or method
@Tenant Use a specifc tenant for the context of a class or method
@WithoutTenant Execute logic without a specific tentnat (using the default connection)
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 46
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 47
Micronaut and Grails
❖ Grails is a rapid-application Java web-framework, based on
Groovy and Spring Boot
❖ Since Grails 4, Grails applications include a Micronaut
application context, allowing Micronaut features and libraries
to be integrated with Grails apps
❖ Micronaut HTTP Client & Grails: https://guides.grails.org/
grails-micronaut-http/guide/index.html
❖ Micronaut Kafka & Grails: https://guides.grails.org/grails-
micronaut-kafka/guide/index.html
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com
❖ Micronaut supports Groovy for writing serverless
functions in environments like AWS Lambda, Oracle
Cloud, Microsoft Azure, & Google Cloud Platform.
❖ You can deploy “pure” functions (invoked by events in
the platform) or lightweight “HTTP functions” (with
controllers, REST endpoints, etc)
48
Micronaut and Groovy: Serverless Functions
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 49
Micronaut and Groovy: Serverless Functions
https://micronaut-projects.github.io/
micronaut-gcp/latest/guide/
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 50
Micronaut and Groovy: Serverless Functions
https://micronaut-projects.github.io/
micronaut-aws/latest/guide/
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 51
Micronaut and Groovy: Serverless Functions
https://micronaut-projects.github.io/
micronaut-azure/latest/guide/
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 52
Micronaut and Groovy: Serverless Functions
https://micronaut-projects.github.io/
micronaut-oracle-cloud/latest/guide/
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 53
Micronaut and Groovy: CLI Apps
❖ Micronaut supports creation of Command Line
Applications using the picocli library (https://picocli.info/)
❖ CLI apps can be created using Groovy as well!
❖ Apps can utilize dependency injection, HTTP clients, &
more
❖ Docs: https://micronaut-projects.github.io/micronaut-
picocli/latest/guide/
© 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 54
Micronaut and Groovy: CLI Apps
objectcomputing.com
© 2022, Object Computing, Inc. (OCI). All rights reserved. No part of these notes may be reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior, written permission of Object Computing, Inc. (OCI)
Zachary Klein, Principal Software Engineer, 2GM Team
1 of 55

Recommended

HTTP Analytics for 6M requests per second using ClickHouse, by Alexander Boc... by
HTTP Analytics for 6M requests per second using ClickHouse, by  Alexander Boc...HTTP Analytics for 6M requests per second using ClickHouse, by  Alexander Boc...
HTTP Analytics for 6M requests per second using ClickHouse, by Alexander Boc...Altinity Ltd
3.5K views21 slides
Scaling Twitter by
Scaling TwitterScaling Twitter
Scaling TwitterBlaine
78.3K views56 slides
React js Demo Explanation by
React js Demo ExplanationReact js Demo Explanation
React js Demo ExplanationRama Krishna Vankam
115 views38 slides
Its time to React.js by
Its time to React.jsIts time to React.js
Its time to React.jsRitesh Mehrotra
3.8K views19 slides
Formation jpa-hibernate-spring-data by
Formation jpa-hibernate-spring-dataFormation jpa-hibernate-spring-data
Formation jpa-hibernate-spring-dataLhouceine OUHAMZA
330 views41 slides
Angular Libraries & NPM by
 Angular Libraries & NPM Angular Libraries & NPM
Angular Libraries & NPMKnoldus Inc.
187 views14 slides

More Related Content

What's hot

Top 100 .NET Interview Questions and Answers by
Top 100 .NET Interview Questions and AnswersTop 100 .NET Interview Questions and Answers
Top 100 .NET Interview Questions and AnswersTung Nguyen Thanh
9K views103 slides
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023 by
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Steve Pember
1.9K views73 slides
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics by
Pragmatic Guide to Apache Kafka®'s Exactly Once SemanticsPragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once Semanticsconfluent
898 views50 slides
API Asynchrones en Java 8 by
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8José Paumard
66K views98 slides
Introduction to ReactJS by
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
2.3K views14 slides
Intro to React by
Intro to ReactIntro to React
Intro to ReactJustin Reock
2.4K views45 slides

What's hot(20)

Top 100 .NET Interview Questions and Answers by Tung Nguyen Thanh
Top 100 .NET Interview Questions and AnswersTop 100 .NET Interview Questions and Answers
Top 100 .NET Interview Questions and Answers
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023 by Steve Pember
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Steve Pember1.9K views
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics by confluent
Pragmatic Guide to Apache Kafka®'s Exactly Once SemanticsPragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics
confluent898 views
API Asynchrones en Java 8 by José Paumard
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
José Paumard66K views
Introduction to ReactJS by Knoldus Inc.
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Knoldus Inc.2.3K views
Build progressive web apps with Angular by Simona Cotin
Build progressive web apps with AngularBuild progressive web apps with Angular
Build progressive web apps with Angular
Simona Cotin2.6K views
Automated Apache Kafka Mocking and Testing with AsyncAPI | Hugo Guerrero, Red... by HostedbyConfluent
Automated Apache Kafka Mocking and Testing with AsyncAPI | Hugo Guerrero, Red...Automated Apache Kafka Mocking and Testing with AsyncAPI | Hugo Guerrero, Red...
Automated Apache Kafka Mocking and Testing with AsyncAPI | Hugo Guerrero, Red...
HostedbyConfluent1.3K views
Rule Engine: Drools .Net by Guo Albert
Rule Engine: Drools .NetRule Engine: Drools .Net
Rule Engine: Drools .Net
Guo Albert7.5K views
Introduction to Node JS.pdf by Bareen Shaikh
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
Bareen Shaikh205 views
Orchestration Patterns for Microservices with Messaging by RabbitMQ by VMware Tanzu
Orchestration Patterns for Microservices with Messaging by RabbitMQOrchestration Patterns for Microservices with Messaging by RabbitMQ
Orchestration Patterns for Microservices with Messaging by RabbitMQ
VMware Tanzu16.4K views
Pros & cons of svelte by ElenorWisozk
Pros & cons of sveltePros & cons of svelte
Pros & cons of svelte
ElenorWisozk418 views
React JS: A Secret Preview by valuebound
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound3.3K views
Fork and join framework by Minh Tran
Fork and join frameworkFork and join framework
Fork and join framework
Minh Tran1.9K views
Nestjs MasterClass Slides by Nir Kaufman
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
Nir Kaufman2.7K views
Uber Real Time Data Analytics by Ankur Bansal
Uber Real Time Data AnalyticsUber Real Time Data Analytics
Uber Real Time Data Analytics
Ankur Bansal2.4K views

Similar to Groovy-Powered Microservices with Micronaut

Micronaut: Changing the Micro Future by
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureZachary Klein
264 views67 slides
Native Cloud-Native: Building Agile Microservices with the Micronaut Framework by
Native Cloud-Native: Building Agile Microservices with the Micronaut FrameworkNative Cloud-Native: Building Agile Microservices with the Micronaut Framework
Native Cloud-Native: Building Agile Microservices with the Micronaut FrameworkZachary Klein
40 views88 slides
Protecting data with CSI Volume Snapshots on Kubernetes by
Protecting data with CSI Volume Snapshots on KubernetesProtecting data with CSI Volume Snapshots on Kubernetes
Protecting data with CSI Volume Snapshots on KubernetesDoKC
56 views18 slides
Quebec - 16 November 2022 - Canada CNCF Meetups.pdf by
Quebec - 16 November 2022 - Canada CNCF Meetups.pdfQuebec - 16 November 2022 - Canada CNCF Meetups.pdf
Quebec - 16 November 2022 - Canada CNCF Meetups.pdfprune1
29 views54 slides
Groovy for Java Devs by
Groovy for Java DevsGroovy for Java Devs
Groovy for Java DevsZachary Klein
658 views64 slides
DevOps for Mainframe: Open Source Fast Track by
DevOps for Mainframe: Open Source Fast TrackDevOps for Mainframe: Open Source Fast Track
DevOps for Mainframe: Open Source Fast TrackDevOps.com
207 views27 slides

Similar to Groovy-Powered Microservices with Micronaut(20)

Micronaut: Changing the Micro Future by Zachary Klein
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
Zachary Klein264 views
Native Cloud-Native: Building Agile Microservices with the Micronaut Framework by Zachary Klein
Native Cloud-Native: Building Agile Microservices with the Micronaut FrameworkNative Cloud-Native: Building Agile Microservices with the Micronaut Framework
Native Cloud-Native: Building Agile Microservices with the Micronaut Framework
Zachary Klein40 views
Protecting data with CSI Volume Snapshots on Kubernetes by DoKC
Protecting data with CSI Volume Snapshots on KubernetesProtecting data with CSI Volume Snapshots on Kubernetes
Protecting data with CSI Volume Snapshots on Kubernetes
DoKC56 views
Quebec - 16 November 2022 - Canada CNCF Meetups.pdf by prune1
Quebec - 16 November 2022 - Canada CNCF Meetups.pdfQuebec - 16 November 2022 - Canada CNCF Meetups.pdf
Quebec - 16 November 2022 - Canada CNCF Meetups.pdf
prune129 views
DevOps for Mainframe: Open Source Fast Track by DevOps.com
DevOps for Mainframe: Open Source Fast TrackDevOps for Mainframe: Open Source Fast Track
DevOps for Mainframe: Open Source Fast Track
DevOps.com207 views
Grails 4: Upgrade your Game! by Zachary Klein
Grails 4: Upgrade your Game!Grails 4: Upgrade your Game!
Grails 4: Upgrade your Game!
Zachary Klein143 views
Get the Exact Identity Solution You Need - In the Cloud - Overview by ForgeRock
Get the Exact Identity Solution You Need - In the Cloud - OverviewGet the Exact Identity Solution You Need - In the Cloud - Overview
Get the Exact Identity Solution You Need - In the Cloud - Overview
ForgeRock437 views
20160221 va interconnect_pub by Canturk Isci
20160221 va interconnect_pub20160221 va interconnect_pub
20160221 va interconnect_pub
Canturk Isci446 views
Kong Academyを日本語でお届け!#4 ”はじめてのKong”オンラインミートアップKong Developer Portal編 by Junji Nishihara
Kong Academyを日本語でお届け!#4 ”はじめてのKong”オンラインミートアップKong Developer Portal編Kong Academyを日本語でお届け!#4 ”はじめてのKong”オンラインミートアップKong Developer Portal編
Kong Academyを日本語でお届け!#4 ”はじめてのKong”オンラインミートアップKong Developer Portal編
Junji Nishihara47 views
Oracle Database Migration to Oracle Cloud Infrastructure by SinanPetrusToma
Oracle Database Migration to Oracle Cloud InfrastructureOracle Database Migration to Oracle Cloud Infrastructure
Oracle Database Migration to Oracle Cloud Infrastructure
SinanPetrusToma1.2K views
Getting Groovy with JHipster and Micronaut by Zachary Klein
Getting Groovy with JHipster and MicronautGetting Groovy with JHipster and Micronaut
Getting Groovy with JHipster and Micronaut
Zachary Klein90 views
RICOH THETA x IoT Developers Contest : Cloud API Seminar by contest-theta360
 RICOH THETA x IoT Developers Contest : Cloud API Seminar RICOH THETA x IoT Developers Contest : Cloud API Seminar
RICOH THETA x IoT Developers Contest : Cloud API Seminar
contest-theta3601.5K views
.NET and Kubernetes: Bringing Legacy .NET Into the Modern World with Pivotal ... by VMware Tanzu
.NET and Kubernetes: Bringing Legacy .NET Into the Modern World with Pivotal ....NET and Kubernetes: Bringing Legacy .NET Into the Modern World with Pivotal ...
.NET and Kubernetes: Bringing Legacy .NET Into the Modern World with Pivotal ...
VMware Tanzu220 views
Introduction to GCCP - 2022.pptx by RamSamarthBB
Introduction to GCCP - 2022.pptxIntroduction to GCCP - 2022.pptx
Introduction to GCCP - 2022.pptx
RamSamarthBB49 views
Gluecon 2017 - GoMake | Flying Dreams: Real-Time Communication from the Edge ... by Jonathan Barton
Gluecon 2017 - GoMake | Flying Dreams: Real-Time Communication from the Edge ...Gluecon 2017 - GoMake | Flying Dreams: Real-Time Communication from the Edge ...
Gluecon 2017 - GoMake | Flying Dreams: Real-Time Communication from the Edge ...
Jonathan Barton383 views
Android Development Workshop by Peter Robinett
Android Development WorkshopAndroid Development Workshop
Android Development Workshop
Peter Robinett14.9K views

More from Zachary Klein

Micronaut Launchpad by
Micronaut LaunchpadMicronaut Launchpad
Micronaut LaunchpadZachary Klein
277 views72 slides
Micronaut For Single Page Apps by
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page AppsZachary Klein
3.4K views61 slides
Grails Launchpad - From Ground Zero to Orbit by
Grails Launchpad - From Ground Zero to OrbitGrails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to OrbitZachary Klein
408 views96 slides
Room with a Vue - Introduction to Vue.js by
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsZachary Klein
820 views45 slides
Shields Up! Securing React Apps by
Shields Up! Securing React AppsShields Up! Securing React Apps
Shields Up! Securing React AppsZachary Klein
398 views48 slides
Using React with Grails 3 by
Using React with Grails 3Using React with Grails 3
Using React with Grails 3Zachary Klein
2.1K views66 slides

More from Zachary Klein(6)

Micronaut For Single Page Apps by Zachary Klein
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
Zachary Klein3.4K views
Grails Launchpad - From Ground Zero to Orbit by Zachary Klein
Grails Launchpad - From Ground Zero to OrbitGrails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to Orbit
Zachary Klein408 views
Room with a Vue - Introduction to Vue.js by Zachary Klein
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
Zachary Klein820 views
Shields Up! Securing React Apps by Zachary Klein
Shields Up! Securing React AppsShields Up! Securing React Apps
Shields Up! Securing React Apps
Zachary Klein398 views
Using React with Grails 3 by Zachary Klein
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
Zachary Klein2.1K views

Recently uploaded

The Forbidden VPN Secrets.pdf by
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdfMariam Shaba
20 views72 slides
Piloting & Scaling Successfully With Microsoft Viva by
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
12 views160 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
58 views8 slides
Scaling Knowledge Graph Architectures with AI by
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
38 views15 slides
Evolving the Network Automation Journey from Python to Platforms by
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
13 views21 slides
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Safe Software
280 views86 slides

Recently uploaded(20)

The Forbidden VPN Secrets.pdf by Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software280 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab21 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely25 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc11 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays22 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker40 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10300 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto12 views

Groovy-Powered Microservices with Micronaut

  • 1. objectcomputing.com © 2022, Object Computing, Inc. (OCI). All rights reserved. No part of these notes may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior, written permission of Object Computing, Inc. (OCI) Groovy-Powered Microservices with Micronaut Zachary Klein, Principal Software Engineer, 2GM Team
  • 2. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ Zachary Klein - Developer & Architect ❖ Principal Software Engineer at Object Computing, Inc ❖ 12+ years of software development experience ❖ OSS contributor ❖ Training instructor 2 About me
  • 3. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. A modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications.
  • 4. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. https://micronaut.io/launch
  • 5. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. ❖ Controller with Dependency Injection
  • 6. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ Micronaut is language-agnostic ❖ 1st Class support for: ❖ Java ❖ Kotlin ❖ Groovy 6 Micronaut and Groovy
  • 7. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ Micronaut implements core framework components using Groovy language features ❖ E.g, Groovy AST transformations are used for AOT compilation support (vs Annotation Processors in Java/Kotlin) ❖ Support for Groovy configuration files, serverless functions, Spock/Geb tests, and GORM! 7 Micronaut and Groovy
  • 8. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. ❖ Controller with Dependency Injection ❖ New class files generated at compilation time (via AST Transformations) to implement the controller, instantiate & supply dependencies, etc
  • 9. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. ❖ Controller with Dependency Injection ❖ New class files generated at compilation time (via AST Transformations) to implement the controller, instantiate & supply dependencies, etc
  • 10. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ Micronaut Launch is the recommended method for creating Micronaut apps ❖ Choose Groovy as the Language (and Spock as testing framework, if desired) ❖ Using the CLI: 10 Getting Started
  • 11. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 11 Getting Started
  • 12. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 12 Getting Started
  • 13. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 13 Getting Started Groovy auto-imports the groovy.lang.singleton annotation - make sure you import from jakarta.inject !
  • 14. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. ❖ Dependency Injection via @Inject
  • 15. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. ❖ Micronaut’s HTTP Client (implemented through Groovy AST Transformations)
  • 16. Copyright © 2022 Object Computing, Inc. (OCI) All rights reserved. ❖ Dependency Injection via Constructor Injection
  • 17. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ YAML is the default, but Groovy is supported ❖ Groovy allows for powerful, expressive, programmatic configuration ❖ Can mix and match! 17 Configuration with Groovy
  • 18. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 18 Configuration with Groovy ❖ Micronaut accepts configuration in JSON, properties, YAML, and Groovy ConfigSlurper (also env variables, system properties) ❖ Note that properties cannot contain dashes - use camelCase or snake_case
  • 19. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ Micronaut Controllers (and Clients) express routes declaratively via annotation arguments: ❖ @Controller("/hello") ❖ @Get("/profile “) ❖ Optionally, routes can be expressed programmatically using the RouteBuilder interface ❖ GroovyRouteBuilder provides an expressive DSL for routes (similar to Grails UrlMappings) 19 Controller Routes
  • 20. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 20 Controller Routes ❖ Annotation-based routes
  • 21. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 21 Controller Routes ❖ GroovyRouteBuilder
  • 22. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 22 @MicronautTest & Spock ❖ Micronaut is test-framework agnostic - no special tooling required ❖ E.g, JUnit, Spock ❖ Because of Micronaut’s fast startup time, many developers prefer integration tests ❖ @MicronautTest automatically starts up the application context for the test run, and shuts it down cleanly
  • 23. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 23 @MicronautTest & Spock
  • 24. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 24 @MicronautTest & Spock
  • 25. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 25 @MicronautTest & Spock
  • 26. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 26 @MicronautTest & Spock
  • 27. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 27 @MicronautTest & Spock
  • 28. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 28 Micronaut and GORM ❖ GORM is the persistence framework pioneered by the Grails framework - https://gorm.grails.org ❖ GORM provides expressive querying, persistence and domain modeling features, including validation, multi-tenancy, and more ❖ When configured with Groovy support, Micronaut apps can leverage GORM’s powerful features in a comparatively lightweight manner
  • 29. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 29 Micronaut and GORM Dependency Description micronaut- hibernate-gorm Configures GORM for Hibernate for Groovy applications micronaut-mongo- gorm Configures GORM for Mongo DB for Groovy applications micronaut-neo4j- gorm Configures GORM for Mongo DB for Groovy applications
  • 30. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 30 Adding GORM to Micronaut ❖ Using Micronaut Launch or the CLI command feature-diff, you can generate a delta showing how to add a feature, like hibernate-gorm
  • 31. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 31 Adding GORM to Micronaut ❖ Add GORM and JDBC dependencies - also a database driver (H2 in this demo)
  • 32. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com Configuring Datasources ❖ Datasource configuration ❖ Standard Hibernate/JDBC configuration properties - database credentials, dialect, etc ❖ Can configure multiple datasources
  • 33. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com Enabling Entity-scanning ❖ Application class needs to be modified ❖ Application context is started up using the builder pattern - the packages() method species the package under which entities are defined
  • 34. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 34 Creating Domain Classes (aka Entities) ❖ A Domain Class / Entity can be a simple POGO annotated with @Entity ❖ Class name will be mapped as database table name (by convention) ❖ Properties of the class will be mapped to columns in the database table
  • 35. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 35 Creating Domain Classes (aka Entities) ❖ Additional data-mapping features (like validation) can be added by implementing the GormEntity<> trait
  • 36. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 36 GORM Data Services in Micronaut
  • 37. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 37 GORM Data Services in Micronaut
  • 38. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 38 GORM Multi-tenancy https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
  • 39. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 39 GORM Multi-tenancy https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
  • 40. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 40 GORM Multi-tenancy https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
  • 41. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 41 GORM Multi-tenancy https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy
  • 42. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 42 GORM Multi-tenancy Modes https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy Modes Description Isolation DATABASE Separate database with a separate connection pool is used to store each tenants data. HIGHEST SCHEMA The same database, but different schemas are used to store each tenants’ data. HIGH DISCRIMINATOR The same database is used with a discriminator used to partition and isolate data. LOW
  • 43. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 43 GORM Multi-tenancy Tenant Resolvers https://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy Name Description CookieTenantResolver Removes the current tenant from an HTTP cookie FixedTenantResolver Resolves against a fixed tenant id HttpHeaderTenantResolver Resolves the current tenant from the request HTTP Header PrincipalTenantResolver Resolves the current tenant from the authenticated username SessionTenantResolver Resolves the current tenant from the HTTP Session SubdomainTenantResolver Resolves the tenant id from the subdomain SystemPropertyTenantResolver Resolves the tenant id from a system property
  • 44. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 44 GORM Multi-tenancy: Specify tenantId
  • 45. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 45 GORM Multi-tenancy Transformations (Annotations) Transformation Description @CurrentTenant Resolve the current tenant for the context of a class or method @Tenant Use a specifc tenant for the context of a class or method @WithoutTenant Execute logic without a specific tentnat (using the default connection)
  • 46. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 46
  • 47. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 47 Micronaut and Grails ❖ Grails is a rapid-application Java web-framework, based on Groovy and Spring Boot ❖ Since Grails 4, Grails applications include a Micronaut application context, allowing Micronaut features and libraries to be integrated with Grails apps ❖ Micronaut HTTP Client & Grails: https://guides.grails.org/ grails-micronaut-http/guide/index.html ❖ Micronaut Kafka & Grails: https://guides.grails.org/grails- micronaut-kafka/guide/index.html
  • 48. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com ❖ Micronaut supports Groovy for writing serverless functions in environments like AWS Lambda, Oracle Cloud, Microsoft Azure, & Google Cloud Platform. ❖ You can deploy “pure” functions (invoked by events in the platform) or lightweight “HTTP functions” (with controllers, REST endpoints, etc) 48 Micronaut and Groovy: Serverless Functions
  • 49. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 49 Micronaut and Groovy: Serverless Functions https://micronaut-projects.github.io/ micronaut-gcp/latest/guide/
  • 50. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 50 Micronaut and Groovy: Serverless Functions https://micronaut-projects.github.io/ micronaut-aws/latest/guide/
  • 51. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 51 Micronaut and Groovy: Serverless Functions https://micronaut-projects.github.io/ micronaut-azure/latest/guide/
  • 52. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 52 Micronaut and Groovy: Serverless Functions https://micronaut-projects.github.io/ micronaut-oracle-cloud/latest/guide/
  • 53. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 53 Micronaut and Groovy: CLI Apps ❖ Micronaut supports creation of Command Line Applications using the picocli library (https://picocli.info/) ❖ CLI apps can be created using Groovy as well! ❖ Apps can utilize dependency injection, HTTP clients, & more ❖ Docs: https://micronaut-projects.github.io/micronaut- picocli/latest/guide/
  • 54. © 2022, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 54 Micronaut and Groovy: CLI Apps
  • 55. objectcomputing.com © 2022, Object Computing, Inc. (OCI). All rights reserved. No part of these notes may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior, written permission of Object Computing, Inc. (OCI) Zachary Klein, Principal Software Engineer, 2GM Team