Google Common
The google-common module provides central configuration for Google connectors in Apache Pekko Connectors as well as basic support for interfacing with Google APIs.
Artifacts
- sbt
val PekkoVersion = "2.0.0" libraryDependencies ++= Seq( "org.apache.pekko" %% "pekko-connectors-google-common" % "2.0.0-RC1", "org.apache.pekko" %% "pekko-stream" % PekkoVersion )- Maven
<properties> <pekko.version>2.0.0</pekko.version> <scala.binary.version>2.13</scala.binary.version> </properties> <dependencies> <dependency> <groupId>org.apache.pekko</groupId> <artifactId>pekko-connectors-google-common_${scala.binary.version}</artifactId> <version>2.0.0-RC1</version> </dependency> <dependency> <groupId>org.apache.pekko</groupId> <artifactId>pekko-stream_${scala.binary.version}</artifactId> <version>${pekko.version}</version> </dependency> </dependencies>- Gradle
def versions = [ PekkoVersion: "2.0.0", ScalaBinary: "2.13" ] dependencies { implementation "org.apache.pekko:pekko-connectors-google-common_${versions.ScalaBinary}:2.0.0-RC1" implementation "org.apache.pekko:pekko-stream_${versions.ScalaBinary}:${versions.PekkoVersion}" }
The table below shows direct dependencies of this module and the second tab shows all libraries it depends on transitively.
- Direct dependencies
Organization Artifact Version com.github.jwt-scala jwt-json-common_2.13 12.0.0 com.google.auth google-auth-library-credentials 1.58.0 com.google.auth google-auth-library-oauth2-http 1.58.0 org.apache.pekko pekko-http-spray-json_2.13 2.0.1 org.apache.pekko pekko-http_2.13 2.0.1 org.apache.pekko pekko-stream_2.13 2.0.0 org.scala-lang scala-library 2.13.18 - Dependency tree
com.github.jwt-scala jwt-json-common_2.13 12.0.0 Apache-2.0 com.github.jwt-scala jwt-core_2.13 12.0.0 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 com.google.auth google-auth-library-credentials 1.58.0 BSD New license org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 com.google.auth google-auth-library-oauth2-http 1.58.0 BSD New license com.google.api api-common 2.74.0 BSD-3-Clause com.google.auto.value auto-value-annotations 1.11.0 Apache 2.0 com.google.code.findbugs jsr305 3.0.2 The Apache Software License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava guava 33.7.2-jre Apache License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava failureaccess 1.0.3 Apache License, Version 2.0 com.google.guava listenablefuture 9999.0-empty-to-avoid-conflict-with-guava The Apache Software License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 com.google.auth google-auth-library-credentials 1.58.0 BSD New license org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 com.google.auto.value auto-value-annotations 1.11.0 Apache 2.0 com.google.code.findbugs jsr305 3.0.2 The Apache Software License, Version 2.0 com.google.code.gson gson 2.14.0 Apache-2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava guava 33.7.2-jre Apache License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava failureaccess 1.0.3 Apache License, Version 2.0 com.google.guava listenablefuture 9999.0-empty-to-avoid-conflict-with-guava The Apache Software License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 com.google.http-client google-http-client-gson 2.2.0 The Apache Software License, Version 2.0 com.google.code.gson gson 2.14.0 Apache-2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.http-client google-http-client 2.2.0 The Apache Software License, Version 2.0 com.google.code.findbugs jsr305 3.0.2 The Apache Software License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava guava 33.7.2-jre Apache License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava failureaccess 1.0.3 Apache License, Version 2.0 com.google.guava listenablefuture 9999.0-empty-to-avoid-conflict-with-guava The Apache Software License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 io.grpc grpc-context 1.70.0 Apache 2.0 io.grpc grpc-api 1.70.0 Apache 2.0 io.opencensus opencensus-api 0.31.1 The Apache License, Version 2.0 io.grpc grpc-context 1.70.0 Apache 2.0 io.grpc grpc-api 1.70.0 Apache 2.0 io.opencensus opencensus-contrib-http-util 0.31.1 The Apache License, Version 2.0 com.google.guava guava 33.7.2-jre Apache License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava failureaccess 1.0.3 Apache License, Version 2.0 com.google.guava listenablefuture 9999.0-empty-to-avoid-conflict-with-guava The Apache Software License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 io.opencensus opencensus-api 0.31.1 The Apache License, Version 2.0 io.grpc grpc-context 1.70.0 Apache 2.0 io.grpc grpc-api 1.70.0 Apache 2.0 org.apache.httpcomponents httpclient 4.5.14 Apache License, Version 2.0 commons-codec commons-codec 1.11 Apache License, Version 2.0 org.apache.httpcomponents httpcore 4.4.16 Apache License, Version 2.0 org.apache.httpcomponents httpcore 4.4.16 Apache License, Version 2.0 com.google.http-client google-http-client 2.2.0 The Apache Software License, Version 2.0 com.google.code.findbugs jsr305 3.0.2 The Apache Software License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava guava 33.7.2-jre Apache License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava failureaccess 1.0.3 Apache License, Version 2.0 com.google.guava listenablefuture 9999.0-empty-to-avoid-conflict-with-guava The Apache Software License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 io.grpc grpc-context 1.70.0 Apache 2.0 io.grpc grpc-api 1.70.0 Apache 2.0 io.opencensus opencensus-api 0.31.1 The Apache License, Version 2.0 io.grpc grpc-context 1.70.0 Apache 2.0 io.grpc grpc-api 1.70.0 Apache 2.0 io.opencensus opencensus-contrib-http-util 0.31.1 The Apache License, Version 2.0 com.google.guava guava 33.7.2-jre Apache License, Version 2.0 com.google.errorprone error_prone_annotations 2.50.0 Apache 2.0 com.google.guava failureaccess 1.0.3 Apache License, Version 2.0 com.google.guava listenablefuture 9999.0-empty-to-avoid-conflict-with-guava The Apache Software License, Version 2.0 com.google.j2objc j2objc-annotations 3.1 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 io.opencensus opencensus-api 0.31.1 The Apache License, Version 2.0 io.grpc grpc-context 1.70.0 Apache 2.0 io.grpc grpc-api 1.70.0 Apache 2.0 org.apache.httpcomponents httpclient 4.5.14 Apache License, Version 2.0 commons-codec commons-codec 1.11 Apache License, Version 2.0 org.apache.httpcomponents httpcore 4.4.16 Apache License, Version 2.0 org.apache.httpcomponents httpcore 4.4.16 Apache License, Version 2.0 org.jspecify jspecify 1.0.1 The Apache License, Version 2.0 org.apache.pekko pekko-http-spray-json_2.13 2.0.1 Apache-2.0 io.spray spray-json_2.13 1.3.6 Apache 2 org.scala-lang scala-library 2.13.18 Apache-2.0 org.apache.pekko pekko-http_2.13 2.0.1 Apache-2.0 org.apache.pekko pekko-http-core_2.13 2.0.1 Apache-2.0 org.apache.pekko pekko-parsing_2.13 2.0.1 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.parboiled parboiled_2.13 2.5.1 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.apache.pekko pekko-http_2.13 2.0.1 Apache-2.0 org.apache.pekko pekko-http-core_2.13 2.0.1 Apache-2.0 org.apache.pekko pekko-parsing_2.13 2.0.1 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.parboiled parboiled_2.13 2.5.1 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.apache.pekko pekko-stream_2.13 2.0.0 Apache-2.0 org.apache.pekko pekko-actor_2.13 2.0.0 Apache-2.0 com.typesafe config 1.4.9 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.apache.pekko pekko-protobuf-v3_2.13 2.0.0 Apache-2.0 org.reactivestreams reactive-streams 1.0.4 MIT-0 org.scala-lang scala-library 2.13.18 Apache-2.0 org.scala-lang scala-library 2.13.18 Apache-2.0
Configuration
Shared settings for all Google connectors are read by default from the pekko.connectors.google configuration section in your application.conf. The available options and their default values are documented in the reference.conf. If you use a non-standard configuration path or need multiple different configurations please refer to the sections below.
source# SPDX-License-Identifier: Apache-2.0
pekko.connectors.google {
credentials {
# Used to build a list of default scopes from each of the modules, don't override
default-scopes = ${?pekko.connectors.google.credentials.default-scopes} []
# Override to specify custom scopes
scopes = ${pekko.connectors.google.credentials.default-scopes}
# Options: application-default, google-application-default, service-account, compute-engine, access-token, none
# application-default first tries service-account, compute-engine then access-token (custom implementation)
# google-application-default delegates to Google's google-auth-library-java which supports all GCP environments
# including GKE Workload Identity
provider = application-default
service-account {
# Config values have first priority, otherwise look for credentials file
project-id = ""
client-email = ""
private-key = ""
# Resolves a path to the well-known credentials file
# See https://github.com/googleapis/google-auth-library-java/blob/master/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java#L237
path = ${user.home}/.config
path = ${?APPDATA} # Windows-only
path = ${pekko.connectors.google.credentials.service-account.path}/gcloud
path = ${?CLOUDSDK_CONFIG}
path = ${pekko.connectors.google.credentials.service-account.path}/application_default_credentials.json
path = ${?GOOGLE_APPLICATION_CREDENTIALS}
}
# Timeout for blocking call during settings initialization to compute engine metadata server
compute-engine.timeout = 1s
user-access {
project-id = ""
client-id = ""
client-secret = ""
refresh-token = ""
# Resolves a path to the well-known credentials file
# See https://github.com/googleapis/google-auth-library-java/blob/master/oauth2_http/java/com/google/auth/oauth2/DefaultCredentialsProvider.java#L237
path = ${user.home}/.config
path = ${?APPDATA} # Windows-only
path = ${pekko.connectors.google.credentials.user-access.path}/gcloud
path = ${?CLOUDSDK_CONFIG}
path = ${pekko.connectors.google.credentials.user-access.path}/application_default_credentials.json
path = ${?GOOGLE_APPLICATION_CREDENTIALS}
}
google-application-default {
project-id = ""
project-id = ${?GOOGLE_CLOUD_PROJECT}
project-id = ${?GCLOUD_PROJECT}
}
access-token {
project-id = ""
token = ""
}
none {
project-id = "<no-project-id>"
}
}
# The GCP project id used for requests to Google APIs.
# If empty, the project id reported by the configured credentials provider is used, and if that is
# empty too, `default-project-id` is used.
# Set this when the project you want to access is not the project that owns the principal the
# credentials authenticate as, which is common when a service account in one project has been
# granted access to resources in another.
project-id = ""
# Fallback project id, used when neither `project-id` nor the credentials provider supplies one.
# These environment variables are commonly set for you by GCP runtimes such as App Engine,
# Cloud Run, Cloud Functions and by GKE Workload Identity.
# Later entries take precedence over earlier ones.
default-project-id = ""
default-project-id = ${?GCP_PROJECT}
default-project-id = ${?GCLOUD_PROJECT}
default-project-id = ${?GOOGLE_CLOUD_PROJECT}
# Standard query parameters for all Google APIs sent with every request
user-ip = ""
quota-user = ""
pretty-print = false
# The minimum size of a chunk, must be a multiple of 256 KiB. See https://github.com/googleapis/java-core/issues/86
upload-chunk-size = 15 MiB
# The retry settings for requests to Google APIs
# Defaults from https://github.com/googleapis/python-api-core/blob/master/google/api_core/retry.py#L72
retry-settings {
max-retries = 6
min-backoff = 1 second
max-backoff = 1 minute
random-factor = 0.2
}
# An address of a proxy that will be used for all connections using HTTP CONNECT tunnel.
# forward-proxy {
# scheme = "https"
# host = "proxy"
# port = 8080
# credentials {
# username = "username"
# password = "password"
# }
# trust-pem = "/path/to/file.pem"
# # Minimum TLS version to use. Valid values: TLSv1.2, TLSv1.3
# # This is only applied when `trust-pem` is set. Without `trust-pem` the connections use
# # the default client HTTPS context of Pekko HTTP, which this setting does not change.
# min-tls-version = "TLSv1.2"
# }
}
Credentials
Credentials will be loaded automatically:
- From the file path specified by the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable or another “well-known” location; or - When running in a Compute Engine instance.
Credentials can also be specified manually in your configuration file.
Credentials that refresh OAuth2 access tokens keep a stream running to cache and renew the token.
Credentials read from an ActorSystem are cached per system and released when it terminates, so they need no special handling. If you build GoogleSettingsGoogleSettings directly from a Config — one set of credentials per tenant, for example — call close() on the credentials when you are done with them to release that stream. Credentials must not be used after they have been closed.
Project id
The project id used for requests is resolved in this order:
- The
pekko.connectors.google.project-idsetting, if it is non-empty; - the project id supplied by the configured credentials provider, if it is non-empty;
- the
pekko.connectors.google.default-project-idsetting, which reads theGOOGLE_CLOUD_PROJECT,GCLOUD_PROJECTandGCP_PROJECTenvironment variables by default.
Setting project-id explicitly is useful because the project that owns the principal your credentials authenticate as need not be the project whose resources you want to access; a service account in one project is often granted access to another. The environment variables behind default-project-id are commonly set for you by GCP runtimes such as App Engine, Cloud Run, Cloud Functions and by GKE Workload Identity.
The resolved value is available as GoogleSettings.projectId and can still be overridden per stream with withProjectId.
Accessing settings
GoogleSettingsGoogleSettings provides methods to retrieve settings from your configuration and GoogleAttributesGoogleAttributes to access the settings attached to a stream. Additionally, if there is an implicit ActorSystemActorSystem in scope, then so will be an implicit instance of the default GoogleSettingsGoogleSettings.
- Scala
-
source
val defaultSettings = GoogleSettings() val customSettings = GoogleSettings("my-app.custom-google-config") Source.fromMaterializer { (mat, attr) => val settings: GoogleSettings = GoogleAttributes.resolveSettings(mat, attr) Source.empty } - Java
-
source
GoogleSettings defaultSettings = GoogleSettings.create(system); GoogleSettings customSettings = GoogleSettings.create("my-app.custom-google-config", system); Source.fromMaterializer( (mat, attr) -> { GoogleSettings settings = GoogleAttributes.resolveSettings(mat, attr); return Source.empty(); });
Apply custom settings to a part of the stream
In certain situations it may be desirable to modify the GoogleSettingsGoogleSettings applied to a part of the stream, for example to use different credentials or change the RetrySettingsRetrySettings. This is accomplished by adding GoogleAttributesGoogleAttributes to your stream.
- Scala
-
source
stream.addAttributes(GoogleAttributes.settingsPath("my-app.custom-google-config")) val defaultSettings = GoogleSettings() val customSettings = defaultSettings.withProjectId("my-other-project") stream.addAttributes(GoogleAttributes.settings(customSettings)) - Java
-
source
stream.addAttributes(GoogleAttributes.settingsPath("my-app.custom-google-config")); GoogleSettings defaultSettings = GoogleSettings.create(system); GoogleSettings customSettings = defaultSettings.withProjectId("my-other-project"); stream.addAttributes(GoogleAttributes.settings(customSettings));
Interop with Google Java client libraries
Instances of the CredentialsCredentials class can be converted via the toGoogle() method to Credentials compatible with Google Java client libraries.
Accessing other Google APIs
The GoogleGoogle object class provides methods for interfacing with Google APIs. You can use it to access APIs that are not currently supported by Apache Pekko Connectors and build new connectors.