The documentation you are viewing is not the latest documentation of Micronaut Gcp

Micronaut GCP

Provides integration between Micronaut and Google Cloud Platform (GCP)

Version: 1.1.0

1 Introduction

This project provides various extensions to Micronaut to integrate Micronaut with Google Cloud Platform (GCP).

2 Setting up GCP Support

The micronaut-gcp-common module includes basic setup for running applications on Google Cloud.

compile 'io.micronaut.gcp:micronaut-gcp-common:1.1.0'
<dependency>
    <groupId>io.micronaut.gcp</groupId>
    <artifactId>micronaut-gcp-common</artifactId>
    <version>1.1.0</version>
</dependency>

Prerequisites:

  1. You should have a Google Cloud Platform project created

  2. Install gcloud CLI

  3. Configure default project gcloud config set project YOUR_PROJECT_ID

  4. Authenticate with gcloud auth login

  5. Authenticate application default credential with gcloud auth application-default login

It’s strongly recommended that you use a Service Account for your application.

Google Project ID

The module features a base GoogleCloudConfiguration which you can use to configure or retrieve the GCP Project ID:

🔗
Table 1. Configuration Properties for GoogleCloudConfiguration
Property Type Description

gcp.project-id

java.lang.String

Sets the project id to use.

You can inject this bean and use the getProjectId() method to retrieve the configured or detected project ID.

Google Credentials

The module will setup a bean of exposing the com.google.auth.oauth2.GoogleCredentials instance that are either detected from the local environment or configured by GoogleCredentialsConfiguration:

🔗
Table 2. Configuration Properties for GoogleCredentialsConfiguration
Property Type Description

gcp.credentials.scopes

java.util.List

The default scopes to associate with the application to access specific APIs. See <a href="https://developers.google.com/identity/protocols/googlescopes">Google Scopes</a> for a complete list. Leave this empty if you don’t need additional API access.

gcp.credentials.encoded-key

java.lang.String

Sets the Base64 encoded service account key content..

gcp.credentials.location

java.lang.String

Sets the location to the service account credential key file.

3 Stackdriver Trace

The micronaut-gcp-tracing integrates Micronaut with Stackdriver Trace.

To enable it add the following dependency:

compile 'io.micronaut.gcp:micronaut-gcp-tracing:1.1.0'
<dependency>
    <groupId>io.micronaut.gcp</groupId>
    <artifactId>micronaut-gcp-tracing</artifactId>
    <version>1.1.0</version>
</dependency>

Then enabling Zipkin tracing in your configuration application.yml:

Enabling Stackdriver Trace
tracing:
    zipkin:
        enabled: true
        # [Optional] Set sampling probability to 100% for dev/testing purposes to observe traces.
        #
        # sampler:
        #    probability=1.0

# [Optional] configuration to enable/disable Stackdriver Trace configuration.
# This is defaulted to true.
#
# gcp:
#    tracing:
#        enabled: true