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 full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size 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 full-size 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 full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size 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 full-size 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 full-size 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 full-size slide