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

    3 MICRONAUT IS LANGUAGE AGNOSTIC
  4. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    4 MICRONAUT IS TEST FRAMEWORK AGNOSTIC
  5. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    5 Micronaut + Groovy ♥
  6. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

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

    7 MICRONAUT LAUNCH - GROOVY/SPOCK
  8. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    8 MICRONAUT CLI - GROOVY/SPOCK
  9. © 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
  10. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    10 Groovy Specific Modules
  11. © 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
  12. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    12 Configuration
  13. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    13 src/main/resources/application.groovy
  14. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    14 Routing
  15. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    15 Using Groovy Route Builder
  16. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    16 Using Groovy Route Builder
  17. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    17 Using @GET @POST @PUT annotations
  18. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    18
  19. © 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
  20. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    20 @AutoCleanup and @Shared
  21. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    21 @AutoCleanup and @Shared
  22. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    22 @AutoCleanup and @Shared
  23. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    23 Spock Mocks
  24. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    24
  25. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    25 geb-spock dependencies
  26. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    26 src/test/resources/GebConfig.groovy
  27. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    27 Webdriver binaries plugin
  28. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    28
  29. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

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

    31 Micronaut + GORM Hibernate
  32. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    32 Hibernate GORM Feature
  33. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    33 Hibernate GORM Feature
  34. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    34 Hibernate GORM | Package scanning
  35. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    35 Entities
  36. © 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.
  37. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

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

    38
  39. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    39 Validation
  40. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    40 Validation
  41. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    41 Multi-Tenancy
  42. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    42 GORM Multitenancy
  43. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    43 GORM MULTITENANCY https://gorm.grails.org/latest/hibernate/ manual/index.html#multiTenancy
  44. © 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.
  45. © 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.
  46. © 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
  47. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

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

    48 DOMAINS MULTI-TENANCY
  49. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    49 DOMAINS - PARTITIONED MULTI-TENANCY
  50. © 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)
  51. © 2018, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com

    51 DOMAINS - PARTITIONED MULTI-TENANCY
  52. © 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
  53. © 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
  54. CONNECT WITH US 1+ (314) 579-0066 @objectcomputing objectcomputing.com © 2019,

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