Camel Components

Huawei Object Storage Service (OBS)

Since Camel 3.12

Both producer and consumer are supported

Huawei Cloud Object Storage Service (OBS) component allows you to integrate with OBS provided by Huawei Cloud.

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

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

URI Format

hwcloud-obs:operation[?options]

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 Huawei Object Storage Service (OBS) component supports the following options which are listed below.

Name Description Default Type

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

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

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

Endpoint Options

The Huawei Object Storage Service (OBS) endpoint is configured using URI syntax:

hwcloud-obs:operation

With the following path and query parameters:

Path Parameters

Name Description Default Type

operation (producer)

Required The operation that the producer performs: listBuckets, createBucket, deleteBucket, checkBucketExists, getBucketMetadata, listObjects, getObject or putObject. The CamelHwCloudObsOperation exchange property replaces this option. The consumer does not use it.

String

Query Parameters

Name Description Default Type

bucketName (common)

The name of the bucket. The consumer requires it and consumes the objects of this bucket. The producer performs the bucket and object operations on it, and the CamelHwCloudObsBucketName exchange property replaces it.

String

endpoint (common)

The endpoint of OBS, as a host name such as obs.cn-north-4.myhuaweicloud.com, optionally with http:// or https:// and a port. Without a scheme, HTTPS is used. When set, the region option is not used.

String

objectName (common)

The name (key) of the object for the getObject and putObject operations. For putObject with a file in the body, the name of the file is used when this option is not set. The CamelHwCloudObsObjectName exchange property replaces this option. The consumer does not use it: see fileName.

String

region (common)

Required The region ID of OBS, for example cn-north-1. When the endpoint option is not set, the client connects to the endpoint of the region, such as obs.cn-north-1.myhuaweicloud.com. Only these regions are accepted: af-south-1, ap-southeast-1, ap-southeast-2, ap-southeast-3, cn-east-2, cn-east-3, cn-north-1, cn-south-1, la-south-2, na-mexico-1, sa-argentina-1, sa-brazil-1, sa-chile-1 and sa-peru-1. For another region, set the endpoint option.

String

deleteAfterRead (consumer)

Whether to delete each consumed object from the bucket once its exchange is complete. When the exchange fails, the object is not deleted. When false, the objects stay in the bucket and later polls consume them again.

false

boolean

delimiter (consumer)

The delimiter, such as /, that groups the keys when the consumer lists the bucket: the objects whose key contains the delimiter after the prefix are grouped into common prefixes and are not consumed, so that only the objects directly under the prefix are consumed. It is not used when fileName is set.

String

destinationBucket (consumer)

The bucket that moveAfterRead copies the consumed objects to, which is required with moveAfterRead. When the consumer starts, it creates this bucket in the location of the source bucket if it does not exist, and fails if it exists in another location.

String

fileName (consumer)

The key of the one object to consume. The consumer then gets this object at each poll instead of listing the bucket, and does not use the prefix, delimiter and maxMessagesPerPoll options. Without deleteAfterRead, the same object is consumed again at each poll.

String

includeFolders (consumer)

Whether to consume the folders too, which are the objects whose key ends with /. When false, the folders are skipped. The objects in a folder are consumed either way.

true

boolean

maxMessagesPerPoll (consumer)

The maximum number of objects that each poll lists, which the consumer passes to OBS as the max-keys of the listing. OBS lists at most 1000 objects per request, and 1000 when this option is 0 or less. The folders that includeFolders=false skips, and the objects that a previous poll is still processing, count too. It is not used when fileName is set.

10

int

moveAfterRead (consumer)

Whether to copy each consumed object, under the same key, to the bucket of the destinationBucket option once its exchange is complete. The object is only copied: set deleteAfterRead too, to remove it from the source bucket. When the exchange fails, the object is not copied.

false

boolean

prefix (consumer)

Consume only the objects whose key starts with this prefix. It is not used when fileName is set.

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

bucketLocation (producer)

The location (region ID) of the bucket that the createBucket operation creates, and that putObject creates when the bucket does not exist. It defaults to cn-north-1 and must be one of the regions that the region option accepts. The CamelHwCloudObsBucketLocation exchange property replaces this option. createBucket does not use it when the body holds the request.

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

proxyHost (proxy)

The host name or IP address of the HTTP proxy server. The client uses a proxy only when this option and the proxyPort option are both set.

String

proxyPassword (proxy)

The password to authenticate with the proxy server. It is used only when the proxyUser option is set.

String

proxyPort (proxy)

The port of the proxy server. The client uses a proxy only when this option and the proxyHost option are both set.

int

proxyUser (proxy)

The user name to authenticate with the proxy server, with basic authentication. It is used only when a proxy is used.

String

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

accessKey (security)

Required The access key ID (AK) of the Huawei Cloud credentials. It is not used when the serviceKeys option is set.

String

ignoreSslVerification (security)

Whether to skip the verification of the TLS certificate of OBS, so that the client trusts any certificate. When false, the certificate is checked against the default trust store of the JVM. Skipping it makes the connection insecure: use it only for testing.

false

boolean

secretKey (security)

Required The secret access key (SK) of the Huawei Cloud credentials. It is not used when the serviceKeys option is set.

String

serviceKeys (security)

The AK/SK pair as an org.apache.camel.component.huaweicloud.common.models.ServiceKeys. When set, its accessKey and secretKey are used instead of the accessKey and secretKey options.

ServiceKeys

Message Headers

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

Name Description Default Type

CamelHwCloudObsBucketName (consumer)

Constant: BUCKET_NAME

The name of the bucket that holds the object.

String

CamelHwCloudObsObjectKey (consumer)

Constant: OBJECT_KEY

The key that the object is stored under.

String

CamelHwCloudObsLastModified (consumer)

Constant: LAST_MODIFIED

The date and time that the object was last modified.

Date

CamelHwCloudObsETag (consumer)

Constant: ETAG

The ETag of the object, which identifies its content. For an object that was not uploaded in parts, it is the MD5 digest of the content in hex, in double quotes as OBS returns it.

String

CamelHwCloudObsContentMD5 (consumer)

Constant: CONTENT_MD5

The MD5 digest of the content of the object in Base64, which the client derives from the ETag. Not set for an object that was uploaded in parts.

String

CamelHwCloudObsObjectType (consumer)

Constant: OBJECT_TYPE

Whether the object is a file or a folder, which is an object whose key ends with /.

String

Content-Length (consumer)

Constant: CONTENT_LENGTH

The size of the object body in bytes.

Long

Content-Type (consumer)

Constant: CONTENT_TYPE

The type of content stored in the object.

String

CamelFileName (consumer)

Constant: FILE_NAME

The key of the object, the same as CamelHwCloudObsObjectKey.

String

Message Body

The message body at each side of the Huawei Object Storage Service (OBS) 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

bytes (byte[])

The content of the object as a byte array, one message per object, with its bucket, key and metadata in headers such as CamelHwCloudObsObjectKey, and the key in CamelFileName too. Folders are consumed too, with an empty body, unless includeFolders=false.

Producer input

any

For putObject the content to upload: text, bytes, a stream or a file, such as the file of a file consumer, whose name is the object name when objectName is not set. A Map or a POJO fails: marshal it first. createBucket takes a CreateBucketRequest of the OBS SDK or its JSON as text, and listObjects a ListObjectsRequest or its JSON, and with another body use the options. The other operations do not use the body.

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

  • With operation=createBucket: text or pojo

  • With operation=listObjects: text or pojo

Producer output

unchanged

The JSON of the result as text: the PutObjectResult of putObject, the array of the objects or the buckets for listObjects and listBuckets, the bucket for createBucket, the response headers for deleteBucket and the metadata for getBucketMetadata. getObject gives the content of the object as a byte array with its metadata in headers. Unchanged after checkBucketExists, which sets the CamelHwCloudObsBucketExists exchange property.

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

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

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

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

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

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

  • With operation=getBucketMetadata: 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

Message properties evaluated by the OBS producer

Header Type Description

CamelHwCloudObsOperation

String

Name of operation to invoke

CamelHwCloudObsBucketName

String

Bucket name to invoke operation on

CamelHwCloudObsBucketLocation

String

Bucket location when creating a new bucket

CamelHwCloudObsObjectName

String

Name of the object to be used in operation. You can also configure the name of the object using this property while performing putObject operation

If any of the above properties are set, they will override their corresponding query parameter.

Message properties set by the OBS producer

Header Type Description

CamelHwCloudObsBucketExists

boolean

Return value when invoking the checkBucketExists operation

List of Supported OBS Operations

  • listBuckets

  • createBucket - bucketName parameter is required, bucketLocation parameter is optional

  • deleteBucket - bucketName parameter is required

  • checkBucketExists - bucketName parameter is required

  • getBucketMetadata - bucketName parameter is required

  • listObjects - bucketName parameter is required

  • getObject - bucketName and objectName parameters are required

  • putObject - bucketName parameter is required. If exchange body contains File, then file name is used as default object name unless over-ridden via exchange property CamelHwCloudObsObjectName

Passing Options Through Exchange Body

There are many options that can be submitted to the createBucket and listObjects operations, so they can be passed through the exchange body.

If you would like to configure all the parameters when creating a bucket, you can pass a CreateBucketRequest object or a Json string into the exchange body. If the exchange body is empty, a new bucket will be created using the bucketName and bucketLocation (if provided) passed through the endpoint uri.

Java-only: requires SDK CreateBucketRequest constructor
from("direct:triggerRoute")
 .setBody(new CreateBucketRequest("Bucket name", "Bucket location"))
 .to("hwcloud-obs:createBucket?region=cn-north-4&accessKey=********&secretKey=********")
  • Java

  • XML

  • YAML

from("direct:triggerRoute")
 .setBody(constant("{\"bucketName\":\"Bucket name\",\"location\":\"Bucket location\"}"))
 .to("hwcloud-obs:createBucket?region=cn-north-4&accessKey=********&secretKey=********")
<route>
  <from uri="direct:triggerRoute"/>
  <setBody>
    <constant>{"bucketName":"Bucket name","location":"Bucket location"}</constant>
  </setBody>
  <to uri="hwcloud-obs:createBucket?region=cn-north-4&amp;accessKey=********&amp;secretKey=********"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setBody:
            constant: '{"bucketName":"Bucket name","location":"Bucket location"}'
        - to:
            uri: hwcloud-obs:createBucket
            parameters:
              region: cn-north-4
              accessKey: "********"
              secretKey: "********"

If you would like to configure all the parameters when listing objects, you can pass a ListObjectsRequest object or a Json string into the exchange body. If the exchange body is empty, objects will be listed based on the bucketName passed through the endpoint uri.

Java-only: requires SDK ListObjectsRequest constructor
from("direct:triggerRoute")
 .setBody(new ListObjectsRequest("Bucket name", 1000))
 .to("hwcloud-obs:listObjects?region=cn-north-4&accessKey=********&secretKey=********")
  • Java

  • XML

  • YAML

from("direct:triggerRoute")
 .setBody(constant("{\"bucketName\":\"Bucket name\",\"maxKeys\":1000}"))
 .to("hwcloud-obs:listObjects?region=cn-north-4&accessKey=********&secretKey=********")
<route>
  <from uri="direct:triggerRoute"/>
  <setBody>
    <constant>{"bucketName":"Bucket name","maxKeys":1000}</constant>
  </setBody>
  <to uri="hwcloud-obs:listObjects?region=cn-north-4&amp;accessKey=********&amp;secretKey=********"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setBody:
            constant: '{"bucketName":"Bucket name","maxKeys":1000}'
        - to:
            uri: hwcloud-obs:listObjects
            parameters:
              region: cn-north-4
              accessKey: "********"
              secretKey: "********"

Using ServiceKey Configuration Bean

Access key and secret keys are required to authenticate against the OBS cloud. You can avoid having them being exposed and scattered over in your endpoint uri by wrapping them inside a bean of class org.apache.camel.component.huaweicloud.common.models.ServiceKeys. Add it to the registry and let Camel look it up by referring the object via endpoint query parameter serviceKeys.

Check the following code snippets:

<bean id="myServiceKeyConfig" class="org.apache.camel.component.huaweicloud.common.models.ServiceKeys">
   <property name="accessKey" value="your_access_key" />
   <property name="secretKey" value="your_secret_key" />
</bean>
  • Java

  • XML

  • YAML

from("direct:triggerRoute")
 .setProperty("CamelHwCloudObsOperation", constant("createBucket"))
 .setProperty("CamelHwCloudObsBucketName", constant("your_bucket_name"))
 .setProperty("CamelHwCloudObsBucketLocation", constant("your_bucket_location"))
 .to("hwcloud-obs:createBucket?region=cn-north-4&serviceKeys=#myServiceKeyConfig")
<route>
  <from uri="direct:triggerRoute"/>
  <setProperty name="CamelHwCloudObsOperation">
    <constant>createBucket</constant>
  </setProperty>
  <setProperty name="CamelHwCloudObsBucketName">
    <constant>your_bucket_name</constant>
  </setProperty>
  <setProperty name="CamelHwCloudObsBucketLocation">
    <constant>your_bucket_location</constant>
  </setProperty>
  <to uri="hwcloud-obs:createBucket?region=cn-north-4&amp;serviceKeys=#myServiceKeyConfig"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setProperty:
            name: CamelHwCloudObsOperation
            constant: createBucket
        - setProperty:
            name: CamelHwCloudObsBucketName
            constant: your_bucket_name
        - setProperty:
            name: CamelHwCloudObsBucketLocation
            constant: your_bucket_location
        - to:
            uri: hwcloud-obs:createBucket
            parameters:
              region: cn-north-4
              serviceKeys: "#myServiceKeyConfig"