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

ApacheCon 2020 Micronaut + Groovy

ApacheCon 2020 Micronaut + Groovy

Talk at ApacheCon 2020 about Micronaut and Groovy.

It covers:

- Micronaut Groovy Dependencies
- Routing
- Configuration
- Micronaut + Spock
- Micronaut + Geb
- GORM for Hibernate
- Micronaut GORM Multi-tenancy

Sergio del Amo

September 30, 2020
Tweet

More Decks by Sergio del Amo

Other Decks in Programming

Transcript

  1. objectcomputing.com © 2019, 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) Micronaut + Groovy
  2. © 2018, Object Computing, Inc. (OCI). All rights reserved. ©

    2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 2 • MICRONAUT / GRAILS OCI TEA M • GUADALAJARA, SPAI N • CURATOR OF GROOVYCALAMARI.COM • GREACH Conference organize r • @SDELAM O • HTTPS://SERGIODELAMO.COM SERGIO DEL AMO
  3. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    6 MICRONAUT IS WRITTEN WITH JAVA. IT IS TESTED WITH SPOCK
  4. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    9 Groovy Specific Modules Dependency Description micronaut-inject-groovy Include AST transformations to generate bean definitions. Should be compileOnly on your classpath. micronaut-runtime-groovy Adds the ability to specify configuration placed in src/main/resources in Groovy format (i.e. application.groovy) micronaut-function-groovy Include AST transforms that make it easier to write Functions for AWS Lambda
  5. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    11 Singleton ⚠ Make sure to use javax.inject.Singleton when declaring a singleton bean. Groovy automatically imports groovy.lang.Singleton
  6. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    19 Test Dependencies org.spockframework:spock-core 2.0-M3-groovy-3.0 org.codehause.groovy:groovy 3.0.4
  7. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    30 GORM Modules 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
  8. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    36 Transaction demarcation ⚠ Each method that interacts with GORM should be annotated with GORM's grails.gorm.transactions.Transactional to ensure a session is present. You can also add the @Transactional annotation to the class.
  9. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    37 GORM Data services are registered automatically a singleton beans
  10. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    43 GORM MULTITENANCY https://gorm.grails.org/latest/hibernate/ manual/index.html#multiTenancy
  11. © 2018, Object Computing, Inc. (OCI). objectcomputing.com 44 GORM Multi-tenancy

    • Configure Multitenancy Mod e • Configure Tenant Resolve r • Configure Domain classes which you want to be regarded as multi tenant. • User Tenants.* or Multi-tenancy Transformations.
  12. © 2018, Object Computing, Inc. (OCI). All rights reserved. ©

    2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 45 Multi-tenancy modes Modes Description DATABASE Separate database with a separate connection pool is used to store each tenants data. SCHEMA The same database, but different schemas are used to store each tenants’ data. DISCRIMINATOR The same database is used with a discriminator used to partition and isolate data.
  13. © 2018, Object Computing, Inc. (OCI). All rights reserved. ©

    2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 46 Multi-tenancy modes - Data isolation Modes Isolation DATABASE SCHEMA DISCRIMINATOR
  14. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    47 MULTI-TENANCY PROPAGATION src/main/resources/application.yml
  15. © 2018, Object Computing, Inc. (OCI). All rights reserved. ©

    2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 50 Multi-tenancy transformations 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)
  16. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    52 Multi-Tenancy GORM - Tenant Resolvers Name Description Cookie Tenant Resolver Removes the current tenant from an HTTP cookie Fixed Tenant Resolver 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
  17. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    • gitter.im/micronautfw • docs.micronaut.io • guides.micronaut.io • micronaut.io/faq.html • github.com/micronaut-projects/micronaut-core • github.com/micronaut-projects/micronaut-examples • objectcomputing.com/products/micronaut • [email protected] Micronaut Resources 53
  18. CONNECT WITH US 1+ (314) 579-0066 @objectcomputing objectcomputing.com © 2019,

    Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 54 Questions?