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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  10. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 10
    Groovy Specific Modules

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  35. © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 35
    Entities

    View Slide

  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.

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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


    https://gorm.grails.org/latest/hibernate/
    manual/index.html#multiTenancy

    View Slide

  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.

    View Slide

  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.

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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)

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  54. CONNECT WITH US
    1+ (314) 579-0066
    @objectcomputing
    objectcomputing.com
    © 2019, Object Computing, Inc. (OCI). All rights reserved. objectcomputing.com 54
    Questions?

    View Slide