Camel Components

IBM Cloud Object Storage

Since Camel 4.16

Both producer and consumer are supported

The IBM COS component supports storing and retrieving objects from/to IBM Cloud Object Storage.

Prerequisites

You must have a valid IBM Cloud account, and be signed up to use IBM Cloud Object Storage. More information is available at IBM Cloud Object Storage.

URI Format

ibm-cos://bucketName[?options]

The bucket is not created when it does not exist, unless the autoCreateBucket option is true.

You can append query options to the URI in the following format:

?options=value&option2=value&…​

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 IBM Cloud Object Storage component supports the following options which are listed below.

Name Description Default Type

autoCreateBucket (common)

Whether to create the bucket when the endpoint starts and the bucket does not exist. Not done when fileName is set.

false

boolean

configuration (common)

The component configuration.

IBMCOSConfiguration

delimiter (common)

The delimiter, such as /, that groups keys when the consumer lists the objects. The objects whose key contains the delimiter after the prefix are rolled up into common prefixes and are not consumed, so only the objects at the level of the prefix are consumed. Only used by the consumer: the listObjects operation takes its delimiter from the CamelIBMCOSDelimiter header.

String

endpointUrl (common)

The URL of the IBM COS endpoint, such as https://s3.us-south.cloud-object-storage.appdomain.cloud. Required unless cosClient is set. Some operations, such as createBucket, need a regional endpoint instead of a cross-region one.

String

location (common)

The location (region) of the bucket, such as us-south or eu-gb. Only reported in the service metadata of the endpoint (for example in the services dev console): the client is not configured with it, its region comes from endpointUrl.

String

prefix (common)

Only consume the objects whose key starts with this prefix, such as inbox/. Only used by the consumer: the listObjects operation takes its prefix from the CamelIBMCOSPrefix header.

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 the object from the bucket after its exchange has been processed successfully. When the processing fails, the object is kept. When false, the object is consumed again by later polls. Not used when moveAfterRead is true.

true

boolean

destinationBucket (consumer)

The bucket that moveAfterRead moves the objects to.

String

destinationBucketPrefix (consumer)

A prefix to add to the key of the object when moveAfterRead copies it to the destination bucket.

String

destinationBucketSuffix (consumer)

A suffix to add to the key of the object when moveAfterRead copies it to the destination bucket.

String

fileName (consumer)

The key of a single object to consume. The consumer then gets only this object on every poll (prefix, delimiter and maxMessagesPerPoll are not used), and the endpoint does not check or create the bucket when it starts.

String

includeBody (consumer)

Whether to set the content of the consumed object as the message body, as a stream. When false, the message has no body, the object is closed right away, and only the headers carry its key and metadata.

true

boolean

includeFolders (consumer)

Whether the consumer also consumes folder markers: empty objects whose key ends with a slash. When false, they are skipped.

true

boolean

moveAfterRead (consumer)

Whether to move the object to the destinationBucket after its exchange has been processed successfully: it is copied to that bucket and then deleted from this one. Takes precedence over deleteAfterRead.

false

boolean

autocloseBody (consumer (advanced))

Whether to close the content stream of the consumed object when its exchange is done. Only applies when includeBody is true. When false, the route must close the stream (the message body) itself, otherwise the HTTP connection is not released.

true

boolean

deleteAfterWrite (producer)

Whether to delete the local file that is the message body (a java.io.File, or the file of the File component) after putObject uploaded it. Other bodies are not affected.

false

boolean

keyName (producer)

The key of the object for the operations that work on one object (putObject, getObject, getObjectRange, deleteObject and copyObject). The CamelIBMCOSKey header overrides it.

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

multiPartUpload (producer)

Whether putObject uploads through the TransferManager of the SDK, which sends a body larger than partSize as a multipart upload. A body of partSize or less is still uploaded in a single request.

false

boolean

operation (producer)

The operation to perform. The CamelIBMCOSOperation header overrides it. When neither is set, putObject is used.

Enum values:

  • copyObject

  • listObjects

  • deleteObject

  • deleteObjects

  • deleteBucket

  • listBuckets

  • getObject

  • getObjectRange

  • headBucket

  • createBucket

  • putObject

IBMCOSOperations

partSize (producer)

The minimum size in bytes of each part of a multipart upload, and the size above which the upload is multipart, when multiPartUpload is true. The TransferManager uses larger parts when needed to stay within 10,000 parts.

26214400

long

storageClass (producer)

The storage class to set on the objects that putObject uploads, sent in the x-amz-storage-class request header.

String

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

cosClient (advanced)

Autowired The IBM COS client (com.ibm.cloud.objectstorage.services.s3.AmazonS3) to use. When set, the apiKey, serviceInstanceId and endpointUrl options are not used, and Camel does not shut the client down.

AmazonS3

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

apiKey (security)

The IBM Cloud API key that the client exchanges for an IBM Cloud IAM token to authenticate. Required unless cosClient is set. HMAC credentials (an access key and a secret key) are not supported here: use a cosClient configured with them instead.

String

serviceInstanceId (security)

The ID of the IBM COS service instance (its resource instance ID, a CRN), sent in the ibm-service-instance-id request header. The createBucket and listBuckets operations, and autoCreateBucket, need it.

String

Endpoint Options

The IBM Cloud Object Storage endpoint is configured using URI syntax:

ibm-cos:bucketName

With the following path and query parameters:

Path Parameters

Name Description Default Type

bucketName (common)

Required The name of the bucket. The consumer consumes its objects, and the producer works on it unless the CamelIBMCOSOverrideBucketName header names another bucket.

String

Query Parameters

Name Description Default Type

autoCreateBucket (common)

Whether to create the bucket when the endpoint starts and the bucket does not exist. Not done when fileName is set.

false

boolean

delimiter (common)

The delimiter, such as /, that groups keys when the consumer lists the objects. The objects whose key contains the delimiter after the prefix are rolled up into common prefixes and are not consumed, so only the objects at the level of the prefix are consumed. Only used by the consumer: the listObjects operation takes its delimiter from the CamelIBMCOSDelimiter header.

String

endpointUrl (common)

The URL of the IBM COS endpoint, such as https://s3.us-south.cloud-object-storage.appdomain.cloud. Required unless cosClient is set. Some operations, such as createBucket, need a regional endpoint instead of a cross-region one.

String

location (common)

The location (region) of the bucket, such as us-south or eu-gb. Only reported in the service metadata of the endpoint (for example in the services dev console): the client is not configured with it, its region comes from endpointUrl.

String

prefix (common)

Only consume the objects whose key starts with this prefix, such as inbox/. Only used by the consumer: the listObjects operation takes its prefix from the CamelIBMCOSPrefix header.

String

deleteAfterRead (consumer)

Whether to delete the object from the bucket after its exchange has been processed successfully. When the processing fails, the object is kept. When false, the object is consumed again by later polls. Not used when moveAfterRead is true.

true

boolean

destinationBucket (consumer)

The bucket that moveAfterRead moves the objects to.

String

destinationBucketPrefix (consumer)

A prefix to add to the key of the object when moveAfterRead copies it to the destination bucket.

String

destinationBucketSuffix (consumer)

A suffix to add to the key of the object when moveAfterRead copies it to the destination bucket.

String

fileName (consumer)

The key of a single object to consume. The consumer then gets only this object on every poll (prefix, delimiter and maxMessagesPerPoll are not used), and the endpoint does not check or create the bucket when it starts.

String

includeBody (consumer)

Whether to set the content of the consumed object as the message body, as a stream. When false, the message has no body, the object is closed right away, and only the headers carry its key and metadata.

true

boolean

includeFolders (consumer)

Whether the consumer also consumes folder markers: empty objects whose key ends with a slash. When false, they are skipped.

true

boolean

maxMessagesPerPoll (consumer)

The maximum number of objects to list, and so to consume, in each poll. The next poll continues the listing where the previous one stopped. Set 0 or a negative value for no limit, in which case IBM COS lists up to 1,000 objects per poll.

10

int

moveAfterRead (consumer)

Whether to move the object to the destinationBucket after its exchange has been processed successfully: it is copied to that bucket and then deleted from this one. Takes precedence over deleteAfterRead.

false

boolean

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

autocloseBody (consumer (advanced))

Whether to close the content stream of the consumed object when its exchange is done. Only applies when includeBody is true. When false, the route must close the stream (the message body) itself, otherwise the HTTP connection is not released.

true

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

inProgressRepository (consumer (advanced))

The repository that holds the keys of the objects being consumed, so a later poll does not consume an object again while its exchange is still in progress. A key is removed when its exchange is done. Defaults to an in-memory repository of up to 10,000 keys.

IdempotentRepository

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

deleteAfterWrite (producer)

Whether to delete the local file that is the message body (a java.io.File, or the file of the File component) after putObject uploaded it. Other bodies are not affected.

false

boolean

keyName (producer)

The key of the object for the operations that work on one object (putObject, getObject, getObjectRange, deleteObject and copyObject). The CamelIBMCOSKey header overrides it.

String

multiPartUpload (producer)

Whether putObject uploads through the TransferManager of the SDK, which sends a body larger than partSize as a multipart upload. A body of partSize or less is still uploaded in a single request.

false

boolean

operation (producer)

The operation to perform. The CamelIBMCOSOperation header overrides it. When neither is set, putObject is used.

Enum values:

  • copyObject

  • listObjects

  • deleteObject

  • deleteObjects

  • deleteBucket

  • listBuckets

  • getObject

  • getObjectRange

  • headBucket

  • createBucket

  • putObject

IBMCOSOperations

partSize (producer)

The minimum size in bytes of each part of a multipart upload, and the size above which the upload is multipart, when multiPartUpload is true. The TransferManager uses larger parts when needed to stay within 10,000 parts.

26214400

long

storageClass (producer)

The storage class to set on the objects that putObject uploads, sent in the x-amz-storage-class request header.

String

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

cosClient (advanced)

Autowired The IBM COS client (com.ibm.cloud.objectstorage.services.s3.AmazonS3) to use. When set, the apiKey, serviceInstanceId and endpointUrl options are not used, and Camel does not shut the client down.

AmazonS3

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

apiKey (security)

The IBM Cloud API key that the client exchanges for an IBM Cloud IAM token to authenticate. Required unless cosClient is set. HMAC credentials (an access key and a secret key) are not supported here: use a cosClient configured with them instead.

String

serviceInstanceId (security)

The ID of the IBM COS service instance (its resource instance ID, a CRN), sent in the ibm-service-instance-id request header. The createBucket and listBuckets operations, and autoCreateBucket, need it.

String

Message Headers

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

Name Description Default Type

CamelIBMCOSBucketName (consumer)

Constant: BUCKET_NAME

The name of the bucket the consumed object is contained in.

String

CamelIBMCOSBucketDestinationName (producer)

Constant: BUCKET_DESTINATION_NAME

The bucket to copy the object to with the copyObject operation.

String

CamelIBMCOSCacheControl (common)

Constant: CACHE_CONTROL

The Cache-Control of the consumed object, which specifies its caching behavior.

String

CamelIBMCOSContentDisposition (common)

Constant: CONTENT_DISPOSITION

The Content-Disposition of the consumed object, such as the recommended file name.

String

CamelIBMCOSContentEncoding (common)

Constant: CONTENT_ENCODING

The Content-Encoding of the consumed object: the content encodings applied to it.

String

CamelIBMCOSContentLength (common)

Constant: CONTENT_LENGTH

The Content-Length HTTP header indicating the size of the associated object in bytes. The putObject operation uses it only for a stream body of unknown length, and takes the length from the body otherwise.

Long

CamelIBMCOSContentMD5 (common)

Constant: CONTENT_MD5

The base64 encoded 128-bit MD5 digest of the object. Not used: the component does not set or read this header.

String

CamelIBMCOSContentType (common)

Constant: CONTENT_TYPE

The Content-Type of the object. The consumer and getObject set it, and putObject stores it with the object.

String

CamelIBMCOSETag (common)

Constant: E_TAG

The ETag of the object. Set by the consumer, getObject and putObject.

String

CamelIBMCOSKey (common)

Constant: KEY

The key of the object. The consumer sets it, and the producer uses it instead of the keyName option.

String

CamelIBMCOSDestinationKey (producer)

Constant: DESTINATION_KEY

The key to copy the object to with the copyObject operation.

String

CamelIBMCOSLastModified (common)

Constant: LAST_MODIFIED

The date and time at which the object was last modified. Set by the consumer and getObject.

Date

CamelIBMCOSVersionId (common)

Constant: VERSION_ID

The version ID of the object, when versioning is enabled on the bucket. Set by the consumer and putObject.

String

CamelIBMCOSOperation (common)

Constant: COS_OPERATION

The operation to perform, instead of the operation option.

String

CamelIBMCOSPrefix (common)

Constant: PREFIX

Only list the objects whose key starts with this prefix, with the listObjects operation. The consumer uses the prefix option instead.

String

CamelIBMCOSDelimiter (common)

Constant: DELIMITER

The delimiter, such as /, that groups keys with the listObjects operation: the objects whose key contains it after the prefix are rolled up into common prefixes and are not listed. The consumer uses the delimiter option instead.

String

CamelIBMCOSKeysToDelete (producer)

Constant: KEYS_TO_DELETE

The list of keys of the objects to delete with the deleteObjects operation.

List

CamelIBMCOSMetadata (common)

Constant: METADATA

The user metadata of the object, as a map. The consumer sets it, and putObject stores it with the object.

Map

CamelIBMCOSRangeStart (producer)

Constant: RANGE_START

The position of the first byte to get with the getObjectRange operation, counted from 0.

Long

CamelIBMCOSRangeEnd (producer)

Constant: RANGE_END

The position of the last byte to get with the getObjectRange operation, inclusive.

Long

CamelIBMCOSBucketExists (producer)

Constant: BUCKET_EXISTS

Whether the bucket exists, set by the headBucket operation. Also true when the bucket exists but access to it is denied.

Boolean

CamelIBMCOSOverrideBucketName (producer)

Constant: OVERRIDE_BUCKET_NAME

The bucket name to use instead of the bucket of the endpoint, in which this object will be stored or which will be used for the current operation.

String

Message Body

The message body at each side of the IBM Cloud Object 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

The content of the object as a stream, one message per object, with its key and metadata in headers. No body with includeBody=false.

  • With includeBody=false: null

Producer input

text, bytes, stream or file

The content to upload with putObject, the default: text, bytes, a stream or a file. A Map, a List or no body fails: marshal it first. The other operations take their input from headers.

  • With operation=putObject: text, bytes, stream or file

Not known when operation is set.

Producer output

unchanged

Unchanged after putObject (with the ETag in a header), copyObject, deleteObject, createBucket and deleteBucket. getObject and getObjectRange give the content as a stream, listObjects a List of the first page of objects, listBuckets a List of Bucket, deleteObjects a List of the deleted objects and headBucket whether the bucket exists.

  • With operation=getObject: stream

  • With operation=getObjectRange: stream

  • With operation=listObjects: list (java.util.List<com.ibm.cloud.objectstorage.services.s3.model.S3ObjectSummary>)

  • With operation=listBuckets: list (java.util.List<com.ibm.cloud.objectstorage.services.s3.model.Bucket>)

  • With operation=deleteObjects: list

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

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.

Required IBM COS component options

You have to provide the apiKey and serviceInstanceId to access IBM Cloud Object Storage, along with the endpointUrl for your region.

Usage

Batch Consumer

This component implements the Batch Consumer.

This allows you, for instance, to know how many messages exist in this batch and for instance, let the Aggregator aggregate this number of messages.

IBM COS Producer operations

The IBM COS component provides the following operation on the producer side:

  • copyObject

  • createBucket

  • deleteBucket

  • deleteObject

  • deleteObjects

  • getObject (this will return an InputStream)

  • getObjectRange (this will return an InputStream with partial content)

  • headBucket

  • listBuckets

  • listObjects

  • putObject

If you don’t specify an operation explicitly, the producer will do:

  • a single file upload

  • a multipart upload if multiPartUpload option is enabled

Content length of putObject

The putObject operation sends the content length of the object with the upload. When the length of the body is known, such as a byte[], a String, a stream cache, a java.io.File, a java.nio.file.Path or the file of the File consumer, that length is used and the CamelIBMCOSContentLength header is ignored. The consumer and getObject set this header to the length of the object they read, so it is wrong once the route changed the body, and the upload would fail.

Only for a stream of unknown length is the CamelIBMCOSContentLength header used, so the stream does not have to be read to know its length. Without the header, the stream is read into a stream cache first to compute its length.

Examples

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

  • Java

  • XML

  • YAML

from("ibm-cos://helloBucket?apiKey=yourApiKey&serviceInstanceId=yourServiceInstanceId&endpointUrl=https://s3.us-south.cloud-object-storage.appdomain.cloud&prefix=hello.txt")
  .to("file:/var/downloaded");
<route>
  <from uri="ibm-cos://helloBucket?apiKey=yourApiKey&amp;serviceInstanceId=yourServiceInstanceId&amp;endpointUrl=https://s3.us-south.cloud-object-storage.appdomain.cloud&amp;prefix=hello.txt"/>
  <to uri="file:/var/downloaded"/>
</route>
- route:
    from:
      uri: ibm-cos://helloBucket
      parameters:
        apiKey: yourApiKey
        serviceInstanceId: yourServiceInstanceId
        endpointUrl: "https://s3.us-south.cloud-object-storage.appdomain.cloud"
        prefix: hello.txt
      steps:
        - to:
            uri: file:/var/downloaded

Advanced IBM COS Client configuration

If your Camel Application is running behind a firewall or if you need to have more control over the AmazonS3 client instance configuration, you can create your own instance and refer to it in your Camel ibm-cos component configuration:

  • Java

  • XML

  • YAML

from("ibm-cos://MyBucket?cosClient=#client&delay=5000&maxMessagesPerPoll=5")
.to("mock:result");
<route>
  <from uri="ibm-cos://MyBucket?cosClient=#client&amp;delay=5000&amp;maxMessagesPerPoll=5"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: ibm-cos://MyBucket
      parameters:
        cosClient: "#client"
        delay: 5000
        maxMessagesPerPoll: 5
      steps:
        - to:
            uri: mock:result

IBM COS Authentication

IBM Cloud Object Storage uses IBM Cloud IAM (Identity and Access Management) for authentication. You need to provide:

You can find your service instance ID and create API keys in the IBM Cloud console.

For more information about IBM COS authentication, see the IBM COS IAM documentation.

IBM COS Endpoints

IBM COS provides different endpoints for different regions and access types (public, private, direct). Examples:

For a complete list of endpoints, see IBM COS Endpoints documentation.

Note that several operations requires a regional endpoint, as opposed to a cross-region endpoint.

IBM COS Producer Operation examples

  • Single Upload: This operation will upload a file to IBM COS based on the body content

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSKey", constant("camel.txt"))
    .setBody(constant("Camel rocks!"))
    .to("ibm-cos://mycamelbucket?apiKey=RAW(myApiKey)&serviceInstanceId=RAW(myServiceInstanceId)&endpointUrl=https://s3.us-south.cloud-object-storage.appdomain.cloud")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSKey">
    <constant>camel.txt</constant>
  </setHeader>
  <setBody>
    <constant>Camel rocks!</constant>
  </setBody>
  <to uri="ibm-cos://mycamelbucket?apiKey=RAW(myApiKey)&amp;serviceInstanceId=RAW(myServiceInstanceId)&amp;endpointUrl=https://s3.us-south.cloud-object-storage.appdomain.cloud"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSKey
            constant: camel.txt
        - setBody:
            constant: "Camel rocks!"
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              apiKey: RAW(myApiKey)
              serviceInstanceId: RAW(myServiceInstanceId)
              endpointUrl: "https://s3.us-south.cloud-object-storage.appdomain.cloud"
        - to:
            uri: mock:result

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

Use RAW() wrapper for sensitive values like API keys to prevent property placeholder resolution.
  • Multipart Upload: This operation will perform a multipart upload of a file to IBM COS based on the body content

Java-only: requires Java File object as body
from("direct:start")
    .setHeader("CamelIBMCOSKey", constant("largefile.zip"))
    .process(exchange -> exchange.getIn().setBody(new File("src/largefile.zip")))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&multiPartUpload=true&partSize=5242880")
    .to("mock:result");

This operation will perform a multipart upload of the file largefile.zip in the mycamelbucket bucket with a part size of 5MB.

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

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSBucketDestinationName", constant("camelDestinationBucket"))
    .setHeader("CamelIBMCOSKey", constant("camelKey"))
    .setHeader("CamelIBMCOSDestinationKey", constant("camelDestinationKey"))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=copyObject")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSBucketDestinationName">
    <constant>camelDestinationBucket</constant>
  </setHeader>
  <setHeader name="CamelIBMCOSKey">
    <constant>camelKey</constant>
  </setHeader>
  <setHeader name="CamelIBMCOSDestinationKey">
    <constant>camelDestinationKey</constant>
  </setHeader>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=copyObject"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSBucketDestinationName
            constant: camelDestinationBucket
        - setHeader:
            name: CamelIBMCOSKey
            constant: camelKey
        - setHeader:
            name: CamelIBMCOSDestinationKey
            constant: camelDestinationKey
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: copyObject
        - to:
            uri: mock:result

This operation will copy the object with the name expressed in the header camelKey to camelDestinationKey in the camelDestinationBucket bucket, from the bucket mycamelbucket.

  • DeleteObject: this operation deletes an object from a bucket

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSKey", constant("camelKey"))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=deleteObject")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSKey">
    <constant>camelKey</constant>
  </setHeader>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=deleteObject"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSKey
            constant: camelKey
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: deleteObject
        - to:
            uri: mock:result

This operation will delete the object camelKey from the bucket mycamelbucket.

  • DeleteObjects: this operation deletes multiple objects from a bucket in a single request

Java-only: requires Java List for keys to delete
from("direct:start")
    .process(exchange -> {
        List<String> keys = Arrays.asList("file1.txt", "file2.txt", "file3.txt");
        exchange.getIn().setHeader("CamelIBMCOSKeysToDelete", keys);
    })
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=deleteObjects")
    .to("mock:result");

This operation will delete the objects file1.txt, file2.txt, and file3.txt from the bucket mycamelbucket in a single batch request.

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

  • Java

  • XML

  • YAML

from("direct:start")
  .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=listBuckets")
  .to("mock:result");
<route>
  <from uri="direct:start"/>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=listBuckets"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              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("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=deleteBucket")
  .to("mock:result");
<route>
  <from uri="direct:start"/>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=deleteBucket"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: deleteBucket
        - to:
            uri: mock:result

This operation will delete the bucket mycamelbucket.

  • CreateBucket: this operation creates a new bucket

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSOverrideBucketName", constant("newBucket"))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=createBucket")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSOverrideBucketName">
    <constant>newBucket</constant>
  </setHeader>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=createBucket"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSOverrideBucketName
            constant: newBucket
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: createBucket
        - to:
            uri: mock:result

This operation will create a new bucket named newBucket.

  • ListObjects: this operation lists objects in a specific bucket

  • Java

  • XML

  • YAML

from("direct:start")
  .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=listObjects")
  .to("mock:result");
<route>
  <from uri="direct:start"/>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=listObjects"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: listObjects
        - to:
            uri: mock:result

This operation will list the objects in the mycamelbucket bucket.

  • ListObjects with prefix: this operation lists objects in a specific bucket with a prefix filter

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSPrefix", constant("backup/"))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=listObjects")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSPrefix">
    <constant>backup/</constant>
  </setHeader>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=listObjects"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSPrefix
            constant: "backup/"
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: listObjects
        - to:
            uri: mock:result

This operation will list only the objects in the mycamelbucket bucket that start with "backup/".

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

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSKey", constant("camelKey"))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=getObject")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSKey">
    <constant>camelKey</constant>
  </setHeader>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=getObject"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSKey
            constant: camelKey
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: getObject
        - to:
            uri: mock:result

This operation will return an InputStream with the content of the camelKey object in mycamelbucket bucket.

  • GetObjectRange: this operation gets a single object range in a specific bucket

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader("CamelIBMCOSKey", constant("camelKey"))
    .setHeader("CamelIBMCOSRangeStart", constant(0L))
    .setHeader("CamelIBMCOSRangeEnd", constant(9L))
    .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=getObjectRange")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelIBMCOSKey">
    <constant>camelKey</constant>
  </setHeader>
  <setHeader name="CamelIBMCOSRangeStart">
    <constant resultType="java.lang.Long">0</constant>
  </setHeader>
  <setHeader name="CamelIBMCOSRangeEnd">
    <constant resultType="java.lang.Long">9</constant>
  </setHeader>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=getObjectRange"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelIBMCOSKey
            constant: camelKey
        - setHeader:
            name: CamelIBMCOSRangeStart
            constant: "0"
        - setHeader:
            name: CamelIBMCOSRangeEnd
            constant: "9"
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: getObjectRange
        - to:
            uri: mock:result

This operation will return an InputStream with the content of the camelKey object in mycamelbucket bucket, containing bytes from 0 to 9.

  • HeadBucket: this operation checks if a bucket exists

  • Java

  • XML

  • YAML

from("direct:start")
  .to("ibm-cos://mycamelbucket?cosClient=#cosClient&operation=headBucket")
  .to("mock:result");
<route>
  <from uri="direct:start"/>
  <to uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;operation=headBucket"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: ibm-cos://mycamelbucket
            parameters:
              cosClient: "#cosClient"
              operation: headBucket
        - to:
            uri: mock:result

This operation will check if the bucket mycamelbucket exists. The result (true/false) will be in the message body. It is also true when the bucket exists but access to it is denied.

IBM COS Consumer

The IBM COS consumer will poll a bucket for new objects and process them.

  • Java

  • XML

  • YAML

from("ibm-cos://mycamelbucket?cosClient=#cosClient&delay=5000&maxMessagesPerPoll=10&deleteAfterRead=true")
  .to("file:/var/downloaded");
<route>
  <from uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;delay=5000&amp;maxMessagesPerPoll=10&amp;deleteAfterRead=true"/>
  <to uri="file:/var/downloaded"/>
</route>
- route:
    from:
      uri: ibm-cos://mycamelbucket
      parameters:
        cosClient: "#cosClient"
        delay: 5000
        maxMessagesPerPoll: 10
        deleteAfterRead: true
      steps:
        - to:
            uri: file:/var/downloaded

This route will poll the mycamelbucket bucket every 5 seconds, processing up to 10 objects per poll, and deleting each object after it’s been successfully processed.

Move After Read

Instead of deleting objects after reading, you can move them to a different bucket or prefix:

  • Java

  • XML

  • YAML

from("ibm-cos://mycamelbucket?cosClient=#cosClient&deleteAfterRead=false&moveAfterRead=true&destinationBucket=processed-bucket&destinationBucketPrefix=done-")
  .to("direct:process");
<route>
  <from uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;deleteAfterRead=false&amp;moveAfterRead=true&amp;destinationBucket=processed-bucket&amp;destinationBucketPrefix=done-"/>
  <to uri="direct:process"/>
</route>
- route:
    from:
      uri: ibm-cos://mycamelbucket
      parameters:
        cosClient: "#cosClient"
        deleteAfterRead: false
        moveAfterRead: true
        destinationBucket: processed-bucket
        destinationBucketPrefix: "done-"
      steps:
        - to:
            uri: direct:process

This route will move processed objects from mycamelbucket to processed-bucket, prefixing each object key with "done-".

IBM COS Consumer with prefix filter

You can filter which objects to consume by using a prefix:

  • Java

  • XML

  • YAML

from("ibm-cos://mycamelbucket?cosClient=#cosClient&prefix=inbox/&deleteAfterRead=true")
  .to("direct:process");
<route>
  <from uri="ibm-cos://mycamelbucket?cosClient=#cosClient&amp;prefix=inbox/&amp;deleteAfterRead=true"/>
  <to uri="direct:process"/>
</route>
- route:
    from:
      uri: ibm-cos://mycamelbucket
      parameters:
        cosClient: "#cosClient"
        prefix: "inbox/"
        deleteAfterRead: true
      steps:
        - to:
            uri: direct:process

This route will only consume objects whose keys start with "inbox/".

Running Integration Tests

Integration tests require valid IBM Cloud credentials. Follow these steps to set up and run the tests.

Creating Service Credentials

  1. Log in to the IBM Cloud Console

  2. Navigate to your Cloud Object Storage instance (or create one if you don’t have one)

  3. Go to Service credentials in the left menu

  4. Click New credential

  5. Give it a name (e.g., camel-cos-test)

  6. Important: Set the role to Manager (required for bucket creation operations)

  7. Click Add

  8. Expand the newly created credential to view the JSON

Mapping Credentials to Test Properties

From the service credential JSON, extract the following values:

System Property JSON Field Example

camel.ibm.cos.apiKey

apikey

Hh1u4wjecZ_jUhJScOt0sN…​

camel.ibm.cos.serviceInstanceId

resource_instance_id

crn:v1:bluemix:public:cloud-object-storage:global:a/…​

camel.ibm.cos.endpointUrl

Not in credentials - choose based on region

https://s3.us-south.cloud-object-storage.appdomain.cloud

The endpoints field in the credentials JSON is a control API URL, not the actual COS endpoint. You must choose a regional endpoint from the IBM COS Endpoints documentation.

Running the Tests

mvn verify -pl components/camel-ibm/camel-ibm-cos \
  -Dcamel.ibm.cos.apiKey=YOUR_API_KEY \
  -Dcamel.ibm.cos.serviceInstanceId='YOUR_SERVICE_INSTANCE_ID' \
  -Dcamel.ibm.cos.endpointUrl=https://s3.us-south.cloud-object-storage.appdomain.cloud
Use single quotes around the serviceInstanceId value to prevent shell interpretation of special characters in the CRN.

Troubleshooting

  • 403 Forbidden: Ensure your service credential has the Manager role. Writer role is not sufficient for bucket creation.

Dependencies

Maven users will need to add the following dependency to their pom.xml.

pom.xml

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

where x.x.x is the version number of Camel.