Camel Components

Google Storage

Since Camel 3.9

Both producer and consumer are supported

The Google Storage component provides access to Google Cloud Storage via the Google java storage library.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-google-storage</artifactId>
    <!-- use the same version as your Camel core version -->
    <version>x.x.x</version>
</dependency>

Authentication Configuration

Google Storage component authentication is targeted for use with the GCP Service Accounts. For more information, please refer to Google Storage Auth Guide.

When you have the service account key, you can provide authentication credentials to your application code. Google security credentials can be set through the component endpoint:

Java-only: constructing the endpoint URI programmatically
String endpoint = "google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json";

Or by providing the path to the GCP credentials file location:

Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS :

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"

Workload Identity Federation

Instead of a service account key, the component can authenticate with Workload Identity Federation, enabled with useWorkloadIdentityFederation=true:

  • With workloadIdentityConfig, the component loads a credential configuration file of type external_account, such as the one that gcloud iam workload-identity-pools create-cred-config generates, and exchanges the token of the external identity provider (AWS, Azure, an OIDC provider) for Google credentials.

  • Without it, the component uses the Application Default Credentials, which detect Workload Identity on GKE.

Set impersonatedServiceAccount to act as a service account with the federated credentials. The federated identity needs the Service Account Token Creator role on that service account.

Java-only: constructing the endpoint URI programmatically
String endpoint = "google-storage://myCamelBucket?useWorkloadIdentityFederation=true"
        + "&workloadIdentityConfig=file:/etc/gcp/wif-config.json"
        + "&impersonatedServiceAccount=storage-writer@my-project.iam.gserviceaccount.com";

URI Format

google-storage://bucketNameOrArn?[options]

By default, the bucket will be created if it doesn’t already exist. You can append query options to the URI in the following format: ?options=value&option2=value&…​

For example, to read file hello.txt from bucket myCamelBucket, use the following snippet:

  • Java

  • XML

  • YAML

from("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&objectName=hello.txt")
    .to("file:/var/downloaded");
<route>
  <from uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;objectName=hello.txt"/>
  <to uri="file:/var/downloaded"/>
</route>
- route:
    from:
      uri: google-storage://myCamelBucket
      parameters:
        serviceAccountKey: /home/user/Downloads/my-key.json
        objectName: hello.txt
      steps:
        - to:
            uri: file:/var/downloaded

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Google Storage component supports the following options which are listed below.

Name Description Default Type

autoCreateBucket (common)

Whether to create a bucket that does not exist, in the storageLocation and with the storageClass. The endpoint checks its bucket when it starts, the consumer checks the destinationBucket of moveAfterRead when it starts, and the producer checks the destination bucket of each copyObject. When false, a missing bucket makes the calls fail.

true

boolean

configuration (common)

The component configuration.

GoogleCloudStorageConfiguration

objectName (common)

The name of the object (Blob) in the bucket. The consumer then polls only this object instead of listing the bucket. The producer uses it as the object of the operation or of the upload, and it takes precedence over the CamelGoogleCloudStorageObjectName header.

String

serviceAccountKey (common)

The service account key file (JSON) used as the credentials of the Storage client. It is loaded as a resource: the classpath:, file:, http: or https: prefix says where from, and a value without a prefix is looked up on the classpath first and then in the file system. When not set, the Application Default Credentials are used, for example from the GOOGLE_APPLICATION_CREDENTIALS environment variable. Not used when useWorkloadIdentityFederation is enabled or when storageClient is set.

String

storageClass (common)

The default storage class of the buckets that the component creates when autoCreateBucket is enabled. An object uploaded without a storage class of its own gets the storage class of its bucket. Not used for a bucket that already exists.

Enum values:

  • STANDARD

  • NEARLINE

  • COLDLINE

  • ARCHIVE

  • REGIONAL

  • MULTI_REGIONAL

  • DURABLE_REDUCED_AVAILABILITY

STANDARD

StorageClass

storageClient (common)

Autowired The Storage client to use. When not set, a single Storage in the registry is used, or else the endpoint creates one, with the credentials that serviceAccountKey and useWorkloadIdentityFederation describe. Those options are not used when a client is set.

Storage

storageLocation (common)

The location, such as US, EU or US-EAST1, of the buckets that the component creates when autoCreateBucket is enabled. Not used for a bucket that already exists.

US-EAST1

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

deleteAfterRead (consumer)

Whether to delete each consumed object from the bucket after its exchange completed successfully. When the exchange fails, the object is not deleted and a later poll consumes it again. When false, the objects stay in the bucket and every poll consumes them again.

true

boolean

destinationBucket (consumer)

The bucket that moveAfterRead copies the consumed objects to. Required when moveAfterRead is enabled. When it does not exist, the consumer creates it at start if autoCreateBucket is enabled.

String

downloadFileName (consumer)

Downloads the content of each consumed object to a local file, whose java.io.File is the message body, instead of into memory. A value without $\{…​} is a directory, and the file is the object name in it: mydownload is the same as mydownload/$\{file:name}. A value with $\{…​} is a file language expression in which $\{file:name} is the object name, such as $\{date:now:yyyyMMdd}/$\{file:name}. The consumer does not create directories: the parent directory of the file must exist. An object name that is absolute or has a .. segment is rejected, as is a file outside the directory before the first $\{…​} (the working directory when there is none). Used only when includeBody is enabled.

String

filter (consumer)

A regular expression that the whole name of an object must match for the consumer to consume it. Not used when objectName is set.

String

includeBody (consumer)

Whether to download the content of the object into the message body. When false, the body is the Blob, which holds the metadata of the object and not its content. The headers with the metadata of the object are set in both cases.

true

boolean

includeFolders (consumer)

Whether to consume the objects whose name ends with a slash (/), which stand for folders. When false, the consumer skips them.

true

boolean

moveAfterRead (consumer)

Whether to copy each consumed object, under the same name, to the destinationBucket after its exchange completed successfully. The object is removed from the bucket only when deleteAfterRead is enabled too (the default); otherwise it stays and a later poll consumes and copies it again. When the exchange fails, the object is not copied.

false

boolean

prefix (consumer)

Consumes only the objects whose name starts with this prefix, which the consumer passes to the listing of the bucket as BlobListOption.prefix. Not used when objectName is set. The listObjects operation of the producer takes its prefix from the CamelGoogleCloudStoragePrefixName header instead.

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

objectStorageClass (producer)

The Cloud Storage class of the objects that the producer uploads. When not set, an object gets the default storage class of its bucket. The CamelGoogleCloudStorageStorageClass header overrides it per message.

Enum values:

  • STANDARD

  • NEARLINE

  • COLDLINE

  • ARCHIVE

  • REGIONAL

  • MULTI_REGIONAL

  • DURABLE_REDUCED_AVAILABILITY

StorageClass

operation (producer)

The operation that the producer performs, when the CamelGoogleCloudStorageOperation header does not set one. When neither sets an operation, the producer uploads the message body as an object.

Enum values:

  • copyObject

  • listObjects

  • deleteObject

  • deleteBucket

  • listBuckets

  • getObject

  • createDownloadLink

GoogleCloudStorageOperations

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

boolean

impersonatedServiceAccount (security)

The email of a service account to impersonate with the credentials of Workload Identity Federation, so the workload gets the permissions of that service account. Used when useWorkloadIdentityFederation is enabled; the federated identity needs the Service Account Token Creator role on the service account.

String

useWorkloadIdentityFederation (security)

Whether to authenticate with Workload Identity Federation instead of a service account key: with the credential configuration file given in workloadIdentityConfig or, when it is not set, with the Application Default Credentials, which detect Workload Identity on GKE.

false

boolean

workloadIdentityConfig (security)

The Workload Identity Federation credential configuration file (JSON, of type external_account), which says how to exchange a token of an external identity provider, such as AWS, Azure or an OIDC provider, for Google credentials. Used when useWorkloadIdentityFederation is enabled. It is loaded as a resource: the classpath:, file:, http: or https: prefix says where from, and a value without a prefix is looked up on the classpath first and then in the file system.

String

Endpoint Options

The Google Storage endpoint is configured using URI syntax:

google-storage:bucketName

With the following path and query parameters:

Path Parameters

Name Description Default Type

bucketName (common)

Required The name of the bucket. A value that starts with arn: is cut to the part after its last colon. The CamelGoogleCloudStorageOverrideBucketName header overrides it for a producer operation.

String

Query Parameters

Name Description Default Type

autoCreateBucket (common)

Whether to create a bucket that does not exist, in the storageLocation and with the storageClass. The endpoint checks its bucket when it starts, the consumer checks the destinationBucket of moveAfterRead when it starts, and the producer checks the destination bucket of each copyObject. When false, a missing bucket makes the calls fail.

true

boolean

objectName (common)

The name of the object (Blob) in the bucket. The consumer then polls only this object instead of listing the bucket. The producer uses it as the object of the operation or of the upload, and it takes precedence over the CamelGoogleCloudStorageObjectName header.

String

serviceAccountKey (common)

The service account key file (JSON) used as the credentials of the Storage client. It is loaded as a resource: the classpath:, file:, http: or https: prefix says where from, and a value without a prefix is looked up on the classpath first and then in the file system. When not set, the Application Default Credentials are used, for example from the GOOGLE_APPLICATION_CREDENTIALS environment variable. Not used when useWorkloadIdentityFederation is enabled or when storageClient is set.

String

storageClass (common)

The default storage class of the buckets that the component creates when autoCreateBucket is enabled. An object uploaded without a storage class of its own gets the storage class of its bucket. Not used for a bucket that already exists.

Enum values:

  • STANDARD

  • NEARLINE

  • COLDLINE

  • ARCHIVE

  • REGIONAL

  • MULTI_REGIONAL

  • DURABLE_REDUCED_AVAILABILITY

STANDARD

StorageClass

storageClient (common)

Autowired The Storage client to use. When not set, a single Storage in the registry is used, or else the endpoint creates one, with the credentials that serviceAccountKey and useWorkloadIdentityFederation describe. Those options are not used when a client is set.

Storage

storageLocation (common)

The location, such as US, EU or US-EAST1, of the buckets that the component creates when autoCreateBucket is enabled. Not used for a bucket that already exists.

US-EAST1

String

deleteAfterRead (consumer)

Whether to delete each consumed object from the bucket after its exchange completed successfully. When the exchange fails, the object is not deleted and a later poll consumes it again. When false, the objects stay in the bucket and every poll consumes them again.

true

boolean

destinationBucket (consumer)

The bucket that moveAfterRead copies the consumed objects to. Required when moveAfterRead is enabled. When it does not exist, the consumer creates it at start if autoCreateBucket is enabled.

String

downloadFileName (consumer)

Downloads the content of each consumed object to a local file, whose java.io.File is the message body, instead of into memory. A value without $\{…​} is a directory, and the file is the object name in it: mydownload is the same as mydownload/$\{file:name}. A value with $\{…​} is a file language expression in which $\{file:name} is the object name, such as $\{date:now:yyyyMMdd}/$\{file:name}. The consumer does not create directories: the parent directory of the file must exist. An object name that is absolute or has a .. segment is rejected, as is a file outside the directory before the first $\{…​} (the working directory when there is none). Used only when includeBody is enabled.

String

filter (consumer)

A regular expression that the whole name of an object must match for the consumer to consume it. Not used when objectName is set.

String

includeBody (consumer)

Whether to download the content of the object into the message body. When false, the body is the Blob, which holds the metadata of the object and not its content. The headers with the metadata of the object are set in both cases.

true

boolean

includeFolders (consumer)

Whether to consume the objects whose name ends with a slash (/), which stand for folders. When false, the consumer skips them.

true

boolean

moveAfterRead (consumer)

Whether to copy each consumed object, under the same name, to the destinationBucket after its exchange completed successfully. The object is removed from the bucket only when deleteAfterRead is enabled too (the default); otherwise it stays and a later poll consumes and copies it again. When the exchange fails, the object is not copied.

false

boolean

prefix (consumer)

Consumes only the objects whose name starts with this prefix, which the consumer passes to the listing of the bucket as BlobListOption.prefix. Not used when objectName is set. The listObjects operation of the producer takes its prefix from the CamelGoogleCloudStoragePrefixName header instead.

String

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

PollingConsumerPollStrategy

objectStorageClass (producer)

The Cloud Storage class of the objects that the producer uploads. When not set, an object gets the default storage class of its bucket. The CamelGoogleCloudStorageStorageClass header overrides it per message.

Enum values:

  • STANDARD

  • NEARLINE

  • COLDLINE

  • ARCHIVE

  • REGIONAL

  • MULTI_REGIONAL

  • DURABLE_REDUCED_AVAILABILITY

StorageClass

operation (producer)

The operation that the producer performs, when the CamelGoogleCloudStorageOperation header does not set one. When neither sets an operation, the producer uploads the message body as an object.

Enum values:

  • copyObject

  • listObjects

  • deleteObject

  • deleteBucket

  • listBuckets

  • getObject

  • createDownloadLink

GoogleCloudStorageOperations

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

healthCheckMaxPollDuration (scheduler)

How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off.

0

long

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler.

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

impersonatedServiceAccount (security)

The email of a service account to impersonate with the credentials of Workload Identity Federation, so the workload gets the permissions of that service account. Used when useWorkloadIdentityFederation is enabled; the federated identity needs the Service Account Token Creator role on the service account.

String

useWorkloadIdentityFederation (security)

Whether to authenticate with Workload Identity Federation instead of a service account key: with the credential configuration file given in workloadIdentityConfig or, when it is not set, with the Application Default Credentials, which detect Workload Identity on GKE.

false

boolean

workloadIdentityConfig (security)

The Workload Identity Federation credential configuration file (JSON, of type external_account), which says how to exchange a token of an external identity provider, such as AWS, Azure or an OIDC provider, for Google credentials. Used when useWorkloadIdentityFederation is enabled. It is loaded as a resource: the classpath:, file:, http: or https: prefix says where from, and a value without a prefix is looked up on the classpath first and then in the file system.

String

Message Headers

The Google Storage component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelGoogleCloudStorageOperation (producer)

Constant: OPERATION

The operation to perform. It takes precedence over the operation option.

Enum values:

  • copyObject

  • listObjects

  • deleteObject

  • deleteBucket

  • listBuckets

  • getObject

  • createDownloadLink

GoogleCloudStorageOperations

CamelGoogleCloudStorageBucketName (consumer)

Constant: BUCKET_NAME

The name of the bucket the object was consumed from.

String

CamelGoogleCloudStorageObjectName (common)

Constant: OBJECT_NAME

The name of the object. The consumer and getObject set it. The producer takes the object of the operation or of the upload from it when the objectName option is not set.

String

CamelGoogleCloudStoragePrefixName (producer)

Constant: PREFIX_NAME

Lists only the objects whose name starts with this prefix, for the listObjects operation.

String

CamelGoogleCloudStorageDestinationObjectName (producer)

Constant: DESTINATION_OBJECT_NAME

The name of the copy, for the copyObject operation, which requires it.

String

CamelGoogleCloudStorageDestinationBucketName (producer)

Constant: DESTINATION_BUCKET_NAME

The bucket to copy the object to, for the copyObject operation, which requires it. The bucket is created when it does not exist and autoCreateBucket is enabled.

String

CamelGoogleCloudStorageDownloadLinkExpirationTime (producer)

Constant: DOWNLOAD_LINK_EXPIRATION_TIME

How long, in milliseconds, the URL of the createDownloadLink operation is valid. The operation signs a V2 URL to GET the object, so the credentials must be able to sign, as service account credentials can.

300000

Long

CamelGoogleCloudStorageContentLength (common)

Constant: CONTENT_LENGTH

The size of the object in bytes, set by the consumer and getObject. On upload, the value, or the length of the body when it is not set, is stored in the custom metadata of the object under the key Content-Length.

Long

CamelGoogleCloudStorageContentType (common)

Constant: CONTENT_TYPE

The content type of the object, set by the consumer and getObject. On upload, it sets the content type of the object.

String

CamelGoogleCloudStorageCacheControl (common)

Constant: CACHE_CONTROL

The Cache-Control metadata of the object, which says whether and how long its content may be cached when it is served. Set by the consumer and getObject. On upload, it sets the Cache-Control of the object.

String

CamelGoogleCloudStorageContentDisposition (common)

Constant: CONTENT_DISPOSITION

The Content-Disposition metadata of the object, set by the consumer and getObject. On upload, it sets the Content-Disposition of the object.

String

CamelGoogleCloudStorageContentEncoding (common)

Constant: CONTENT_ENCODING

The Content-Encoding metadata of the object, such as gzip, set by the consumer and getObject. On upload, it sets the Content-Encoding of the object.

String

CamelGoogleCloudStorageContentMd5 (common)

Constant: CONTENT_MD5

The MD5 hash of the content of the object. The consumer and getObject set it as a hexadecimal string. On upload, it sets the MD5 hash of the object, which the library expects base64 encoded. As the two formats differ, do not pass the consumed value as is to an upload.

String

CamelFileName (consumer)

Constant: FILE_NAME

The name of the object. The consumer sets it only when downloadFileName is set, as the $\{file:name} of that expression.

String

CamelGoogleCloudStorageComponentCount (common)

Constant: METADATA_COMPONENT_COUNT

The number of components of a composite object, one made by composing other objects.

Integer

CamelGoogleCloudStorageContentLanguage (common)

Constant: METADATA_CONTENT_LANGUAGE

The Content-Language metadata of the object: the language of its content. Set by the consumer and getObject; not used on upload.

String

CamelGoogleCloudStorageCustomTime (common)

Constant: METADATA_CUSTOM_TIME

The Custom-Time metadata of the object, in milliseconds since the epoch: a date and time that the user sets, typically for the DaysSinceCustomTime condition of Object Lifecycle Management. Set by the consumer and getObject; not used on upload.

Long

CamelGoogleCloudStorageCrc32cHex (common)

Constant: METADATA_CRC32C_HEX

The CRC32C checksum of the content of the object, as a hexadecimal string.

String

CamelGoogleCloudStorageETag (common)

Constant: METADATA_ETAG

The ETag of the object.

String

CamelGoogleCloudStorageGeneration (common)

Constant: METADATA_GENERATION

The generation of the object: the version of its content, which changes each time the object is written.

Long

CamelGoogleCloudStorageBlobId (common)

Constant: METADATA_BLOB_ID

The BlobId of the object: its bucket, name and generation.

BlobId

CamelGoogleCloudStorageKmsKeyName (common)

Constant: METADATA_KMS_KEY_NAME

The name of the Cloud KMS key that encrypts the object, when it is encrypted with a customer-managed key.

String

CamelGoogleCloudStorageMediaLink (common)

Constant: METADATA_MEDIA_LINK

The media link of the object: the URL to download its content.

String

CamelGoogleCloudStorageMetageneration (common)

Constant: METADATA_METAGENERATION

The metageneration of the object: the version of its metadata, which changes each time the metadata is updated.

Long

CamelGoogleCloudStorageStorageClass (common)

Constant: METADATA_STORAGE_CLASS

The storage class of the object. When uploading an object, it sets the storage class of the object, and takes precedence over the objectStorageClass option; a name such as NEARLINE can be given.

StorageClass

CamelGoogleCloudStorageCreateTime (common)

Constant: METADATA_CREATE_TIME

The time the object was created, in milliseconds since the epoch.

Long

CamelGoogleCloudStorageLastUpdate (common)

Constant: METADATA_LAST_UPDATE

The time the metadata of the object was last updated.

Date

CamelGoogleCloudStorageOverrideBucketName (common)

Constant: OVERRIDE_BUCKET_NAME

The bucket of the producer operation or upload, instead of the bucket of the endpoint. Not used by listBuckets. The bucket is not created when it does not exist.

String

Message Body

The message body at each side of the Google Storage component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

stream, bytes or file

The content of the object, one message per object, with its metadata in headers: a stream cache, or a byte array when stream caching is off. With downloadFileName the java.io.File it is downloaded to, and with includeBody=false the Blob, which has the metadata and not the content.

  • With includeBody=false: pojo (com.google.cloud.storage.Blob)

Producer input

text, bytes, stream or file

The content to upload, when no operation is set: text, bytes, a stream or a file. A Map, a List or no body fails: marshal it first. The operations take their input from options and headers.

Not known when operation is set.

Producer output

pojo (com.google.cloud.storage.Blob)

The Blob of the uploaded object. By the operation: the content as a byte array for getObject, with its metadata in headers, a List of Blob or Bucket for the lists, the CopyWriter for copyObject, whose getResult() gives the Blob of the copy, true or false for the deletes and the signed URL as text for createDownloadLink.

  • With operation=getObject: bytes (byte[])

  • With operation=listObjects: list (java.util.List<com.google.cloud.storage.Blob>)

  • With operation=listBuckets: list (java.util.List<com.google.cloud.storage.Bucket>)

  • With operation=copyObject: pojo (com.google.cloud.storage.CopyWriter)

  • With operation=deleteObject: value (java.lang.Boolean)

  • With operation=deleteBucket: value (java.lang.Boolean)

  • With operation=createDownloadLink: text (java.lang.String)

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Google Storage Producer operations

Google Storage component provides the following operations on the producer side:

  • copyObject

  • listObjects

  • deleteObject

  • deleteBucket

  • listBuckets

  • getObject

  • createDownloadLink

If you don’t specify an operation explicitly, the producer uploads a file.

Advanced component configuration

If you need to have more control over the storageClient instance configuration, you can create your own instance and refer to it in your Camel google-storage component configuration:

  • Java

  • XML

  • YAML

from("google-storage://myCamelBucket?storageClient=#client")
    .to("mock:result");
<route>
  <from uri="google-storage://myCamelBucket?storageClient=#client"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: google-storage://myCamelBucket
      parameters:
        storageClient: "#client"
      steps:
        - to:
            uri: mock:result

Google Storage Producer Operation examples

  • File Upload: This operation will upload a file to the Google Storage based on the body content

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelGoogleCloudStorageObjectName").constant("camel.txt")
    .setBody().constant("Camel rocks!")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json")
    .log("uploaded file object:${header.CamelGoogleCloudStorageObjectName}, body:${body}");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelGoogleCloudStorageObjectName">
    <constant>camel.txt</constant>
  </setHeader>
  <setBody>
    <constant>Camel rocks!</constant>
  </setBody>
  <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json"/>
  <log message="uploaded file object:${header.CamelGoogleCloudStorageObjectName}, body:${body}"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelGoogleCloudStorageObjectName
            constant: camel.txt
        - setBody:
            constant: "Camel rocks!"
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
        - log:
            message: "uploaded file object:${header.CamelGoogleCloudStorageObjectName}, body:${body}"

This operation will upload the file camel.txt with the content "Camel rocks!" in the myCamelBucket bucket

  • CopyObject: this operation copies an object from one bucket to a different one

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelGoogleCloudStorageObjectName").constant("camel.txt")
    .setHeader("CamelGoogleCloudStorageDestinationBucketName").constant("myCamelBucket_dest")
    .setHeader("CamelGoogleCloudStorageDestinationObjectName").constant("camel_copy.txt")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=copyObject")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelGoogleCloudStorageObjectName">
    <constant>camel.txt</constant>
  </setHeader>
  <setHeader name="CamelGoogleCloudStorageDestinationBucketName">
    <constant>myCamelBucket_dest</constant>
  </setHeader>
  <setHeader name="CamelGoogleCloudStorageDestinationObjectName">
    <constant>camel_copy.txt</constant>
  </setHeader>
  <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=copyObject"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelGoogleCloudStorageObjectName
            constant: camel.txt
        - setHeader:
            name: CamelGoogleCloudStorageDestinationBucketName
            constant: myCamelBucket_dest
        - setHeader:
            name: CamelGoogleCloudStorageDestinationObjectName
            constant: camel_copy.txt
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: copyObject
        - to:
            uri: mock:result

This operation will copy the object with the name expressed in the header DESTINATION_OBJECT_NAME to the DESTINATION_BUCKET_NAME bucket, from the bucket myCamelBucket.

  • DeleteObject: this operation deletes an object from a bucket

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelGoogleCloudStorageObjectName").constant("camel.txt")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=deleteObject")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelGoogleCloudStorageObjectName">
    <constant>camel.txt</constant>
  </setHeader>
  <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=deleteObject"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelGoogleCloudStorageObjectName
            constant: camel.txt
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: deleteObject
        - to:
            uri: mock:result

This operation will delete the object from the bucket myCamelBucket.

  • ListBuckets: this operation lists the buckets for this account in this region

  • Java

  • XML

  • YAML

from("direct:start")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=listBuckets")
    .to("mock:result");
<route>
    <from uri="direct:start"/>
    <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=listBuckets"/>
    <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: listBuckets
        - to:
            uri: mock:result

This operation will list the buckets for this account.

  • DeleteBucket: this operation deletes the bucket specified as URI parameter or header

  • Java

  • XML

  • YAML

from("direct:start")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=deleteBucket")
    .to("mock:result");
<route>
    <from uri="direct:start"/>
    <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=deleteBucket"/>
    <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: deleteBucket
        - to:
            uri: mock:result

This operation will delete the bucket myCamelBucket.

  • ListObjects: this operation list object in a specific bucket

  • Java

  • XML

  • YAML

from("direct:start")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=listObjects")
    .to("mock:result");
<route>
    <from uri="direct:start"/>
    <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=listObjects"/>
    <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: listObjects
        - to:
            uri: mock:result

This operation will list the objects in the myCamelBucket bucket.

  • GetObject: this operation gets a single object in a specific bucket

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelGoogleCloudStorageObjectName").constant("camel.txt")
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=getObject")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelGoogleCloudStorageObjectName">
    <constant>camel.txt</constant>
  </setHeader>
  <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=getObject"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelGoogleCloudStorageObjectName
            constant: camel.txt
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: getObject
        - to:
            uri: mock:result

This operation will return the content of the OBJECT_NAME object in myCamelBucket bucket as a byte array, with its metadata in headers.

  • CreateDownloadLink: this operation will return a download link

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelGoogleCloudStorageObjectName").constant("camel.txt")
    .setHeader("CamelGoogleCloudStorageDownloadLinkExpirationTime").constant(86400000L)
    .to("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&operation=createDownloadLink")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelGoogleCloudStorageObjectName">
    <constant>camel.txt</constant>
  </setHeader>
  <setHeader name="CamelGoogleCloudStorageDownloadLinkExpirationTime">
    <constant resultType="java.lang.Long">86400000</constant>
  </setHeader>
  <to uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;operation=createDownloadLink"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelGoogleCloudStorageObjectName
            constant: camel.txt
        - setHeader:
            name: CamelGoogleCloudStorageDownloadLinkExpirationTime
            constant: "86400000"
        - to:
            uri: google-storage://myCamelBucket
            parameters:
              serviceAccountKey: /home/user/Downloads/my-key.json
              operation: createDownloadLink
        - to:
            uri: mock:result

This operation will return a download link url for the file OBJECT_NAME in the bucket myCamelBucket. It’s possible to specify the expiration time for the created link through the header DOWNLOAD_LINK_EXPIRATION_TIME. If not specified, by default it is 5 minutes.

Bucket Auto creation

With the option autoCreateBucket users are able to avoid the autocreation of a Bucket in case it doesn’t exist. The default for this option is true. If set to false, any operation on a not-existent bucket won’t be successful and an error will be returned.

Storage class

The storageClass option sets the storage class of a bucket that the component creates (see autoCreateBucket). The objects in a bucket get the default storage class of the bucket.

To upload an object with another storage class, for example an archive file as COLDLINE into a STANDARD bucket, set the producer option objectStorageClass, or the CamelGoogleCloudStorageStorageClass header for each message. The header takes precedence over the option.

from("direct:archive")
    .to("google-storage://myCamelBucket?objectStorageClass=COLDLINE");

The consumer and the getObject operation set the CamelGoogleCloudStorageStorageClass header to the storage class of the object they read. A route that copies objects from one bucket to another with the producer therefore keeps the storage class of each object. Remove the header to use the objectStorageClass option or the default of the destination bucket instead.

MoveAfterRead consumer option

In addition to deleteAfterRead it has been added another option, moveAfterRead. With this option enabled the consumed object will be moved to a target destinationBucket instead of being only deleted. This will require specifying the destinationBucket option. As example:

  • Java

  • XML

  • YAML

from("google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&autoCreateBucket=true&destinationBucket=myCamelProcessedBucket&moveAfterRead=true&deleteAfterRead=true&includeBody=true")
    .to("mock:result");
<route>
  <from uri="google-storage://myCamelBucket?serviceAccountKey=/home/user/Downloads/my-key.json&amp;autoCreateBucket=true&amp;destinationBucket=myCamelProcessedBucket&amp;moveAfterRead=true&amp;deleteAfterRead=true&amp;includeBody=true"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: google-storage://myCamelBucket
      parameters:
        serviceAccountKey: /home/user/Downloads/my-key.json
        autoCreateBucket: true
        destinationBucket: myCamelProcessedBucket
        moveAfterRead: true
        deleteAfterRead: true
        includeBody: true
      steps:
        - to:
            uri: mock:result

In this case, the objects consumed will be moved to myCamelProcessedBucket bucket and deleted from the original one (because of deleteAfterRead).

The consumer deletes or moves the object it consumed, whatever the route does with the CamelGoogleCloudStorageObjectName and CamelGoogleCloudStorageBucketName headers. A route can set the object name header to write a copy of the object under another name.