Camel Spring Boot Reference
Camel Spring Boot Reference
Abstract
Preface
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.
Chapter 1. AWS CloudWatch
Only producer is supported
The AWS2 Cloudwatch component allows messages to be sent to an Amazon CloudWatch metrics. The implementation of the Amazon API is provided by the AWS SDK.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon CloudWatch. More information is available at Amazon CloudWatch.
1.1. URI Format
aws2-cw://namespace[?options]
The metrics will be created if they don’t already exists. You can append query options to the URI in the following format, ?options=value&option2=value&…
1.2. Configuring Options
Camel components are configured on two separate levels:
- component level
- endpoint level
1.2.1. Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
1.2.2. Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
1.3. Component Options
The AWS CloudWatch component supports 18 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
amazonCwClient (producer) | Autowired To use the AmazonCloudWatch as the client. | CloudWatchClient | |
configuration (producer) | The component configuration. | Cw2Configuration | |
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 |
name (producer) | The metric name. | String | |
overrideEndpoint (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
proxyHost (producer) | To define a proxy host when instantiating the CW client. | String | |
proxyPort (producer) | To define a proxy port when instantiating the CW client. | Integer | |
proxyProtocol (producer) | To define a proxy protocol when instantiating the CW client. Enum values:
| HTTPS | Protocol |
region (producer) | The region in which CW client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
timestamp (producer) | The metric timestamp. | Instant | |
trustAllCertificates (producer) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
unit (producer) | The metric unit. | String | |
uriEndpointOverride (producer) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (producer) | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
value (producer) | The metric value. | Double | |
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 |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
1.4. Endpoint Options
The AWS CloudWatch endpoint is configured using URI syntax:
aws2-cw:namespace
with the following path and query parameters:
1.4.1. Path Parameters (1 parameters)
Name | Description | Default | Type |
---|---|---|---|
namespace (producer) | Required The metric namespace. | String |
1.4.2. Query Parameters (16 parameters)
Name | Description | Default | Type |
---|---|---|---|
amazonCwClient (producer) | Autowired To use the AmazonCloudWatch as the client. | CloudWatchClient | |
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 |
name (producer) | The metric name. | String | |
overrideEndpoint (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
proxyHost (producer) | To define a proxy host when instantiating the CW client. | String | |
proxyPort (producer) | To define a proxy port when instantiating the CW client. | Integer | |
proxyProtocol (producer) | To define a proxy protocol when instantiating the CW client. Enum values:
| HTTPS | Protocol |
region (producer) | The region in which CW client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
timestamp (producer) | The metric timestamp. | Instant | |
trustAllCertificates (producer) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
unit (producer) | The metric unit. | String | |
uriEndpointOverride (producer) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (producer) | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
value (producer) | The metric value. | Double | |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
Required CW component options
You have to provide the amazonCwClient in the Registry or your accessKey and secretKey to access the Amazon’s CloudWatch.
1.5. Usage
1.5.1. Static credentials vs Default Credential Provider
You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.
- Java system properties - aws.accessKeyId and aws.secretKey
- Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
- Web Identity Token from AWS STS.
- The shared credentials and config files.
- Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
- Amazon EC2 Instance profile credentials.
For more information about this you can look at AWS credentials documentation
1.5.2. Message headers evaluated by the CW producer
Header | Type | Description |
---|---|---|
|
| The Amazon CW metric name. |
|
| The Amazon CW metric value. |
|
| The Amazon CW metric unit. |
|
| The Amazon CW metric namespace. |
|
| The Amazon CW metric timestamp. |
|
| The Amazon CW metric dimension name. |
|
| The Amazon CW metric dimension value. |
|
| A map of dimension names and dimension values. |
1.5.3. Advanced CloudWatchClient configuration
If you need more control over the CloudWatchClient
instance configuration you can create your own instance and refer to it from the URI:
from("direct:start") .to("aws2-cw://namespace?amazonCwClient=#client");
The #client
refers to a CloudWatchClient
in the Registry.
1.6. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws2-cw</artifactId> <version>${camel-version}</version> </dependency>
where {camel-version
} must be replaced by the actual version of Camel.
1.7. Examples
1.7.1. Producer Example
from("direct:start") .to("aws2-cw://http://camel.apache.org/aws-cw");
and sends something like
exchange.getIn().setHeader(Cw2Constants.METRIC_NAME, "ExchangesCompleted"); exchange.getIn().setHeader(Cw2Constants.METRIC_VALUE, "2.0"); exchange.getIn().setHeader(Cw2Constants.METRIC_UNIT, "Count");
1.8. Spring Boot Auto-Configuration
When using aws2-cw with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-aws2-cw-starter</artifactId> <version>{CamelSBProjectVersion}</version> <!-- Use your Camel Spring Boot version --> </dependency>
The component supports 19 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws2-cw.access-key | Amazon AWS Access Key. | String | |
camel.component.aws2-cw.amazon-cw-client | To use the AmazonCloudWatch as the client. The option is a software.amazon.awssdk.services.cloudwatch.CloudWatchClient type. | CloudWatchClient | |
camel.component.aws2-cw.autowired-enabled | 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 |
camel.component.aws2-cw.configuration | The component configuration. The option is a org.apache.camel.component.aws2.cw.Cw2Configuration type. | Cw2Configuration | |
camel.component.aws2-cw.enabled | Whether to enable auto configuration of the aws2-cw component. This is enabled by default. | Boolean | |
camel.component.aws2-cw.lazy-start-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 |
camel.component.aws2-cw.name | The metric name. | String | |
camel.component.aws2-cw.override-endpoint | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | Boolean |
camel.component.aws2-cw.proxy-host | To define a proxy host when instantiating the CW client. | String | |
camel.component.aws2-cw.proxy-port | To define a proxy port when instantiating the CW client. | Integer | |
camel.component.aws2-cw.proxy-protocol | To define a proxy protocol when instantiating the CW client. | Protocol | |
camel.component.aws2-cw.region | The region in which CW client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
camel.component.aws2-cw.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws2-cw.timestamp | The metric timestamp. The option is a java.time.Instant type. | Instant | |
camel.component.aws2-cw.trust-all-certificates | If we want to trust all certificates in case of overriding the endpoint. | false | Boolean |
camel.component.aws2-cw.unit | The metric unit. | String | |
camel.component.aws2-cw.uri-endpoint-override | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
camel.component.aws2-cw.use-default-credentials-provider | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | Boolean |
camel.component.aws2-cw.value | The metric value. | Double |
Chapter 2. AWS DynamoDB
Only producer is supported
The AWS2 DynamoDB component supports storing and retrieving data from/to service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon DynamoDB. More information is available at Amazon DynamoDB.
2.1. URI Format
aws2-ddb://domainName[?options]
You can append query options to the URI in the following format, ?options=value&option2=value&…
2.2. Configuring Options
Camel components are configured on two separate levels:
- component level
- endpoint level
2.2.1. Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
2.2.2. Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
2.3. Component Options
The AWS DynamoDB component supports 22 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
amazonDDBClient (producer) | Autowired To use the AmazonDynamoDB as the client. | DynamoDbClient | |
configuration (producer) | The component configuration. | Ddb2Configuration | |
consistentRead (producer) | Determines whether or not strong consistency should be enforced when data is read. | false | boolean |
enabledInitialDescribeTable (producer) | Set whether the initial Describe table operation in the DDB Endpoint must be done, or not. | true | boolean |
keyAttributeName (producer) | Attribute name when creating table. | String | |
keyAttributeType (producer) | Attribute type when creating table. | String | |
keyScalarType (producer) | The key scalar type, it can be S (String), N (Number) and B (Bytes). | 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 |
operation (producer) | What operation to perform. Enum values:
| PutItem | Ddb2Operations |
overrideEndpoint (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
proxyHost (producer) | To define a proxy host when instantiating the DDB client. | String | |
proxyPort (producer) | The region in which DynamoDB client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | Integer | |
proxyProtocol (producer) | To define a proxy protocol when instantiating the DDB client. Enum values:
| HTTPS | Protocol |
readCapacity (producer) | The provisioned throughput to reserve for reading resources from your table. | Long | |
region (producer) | The region in which DDB client needs to work. | String | |
trustAllCertificates (producer) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (producer) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (producer) | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
writeCapacity (producer) | The provisioned throughput to reserved for writing resources to your table. | Long | |
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 |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
2.4. Endpoint Options
The AWS DynamoDB endpoint is configured using URI syntax:
aws2-ddb:tableName
with the following path and query parameters:
2.4.1. Path Parameters (1 parameters)
Name | Description | Default | Type |
---|---|---|---|
tableName (producer) | Required The name of the table currently worked with. | String |
2.4.2. Query Parameters (20 parameters)
Name | Description | Default | Type |
---|---|---|---|
amazonDDBClient (producer) | Autowired To use the AmazonDynamoDB as the client. | DynamoDbClient | |
consistentRead (producer) | Determines whether or not strong consistency should be enforced when data is read. | false | boolean |
enabledInitialDescribeTable (producer) | Set whether the initial Describe table operation in the DDB Endpoint must be done, or not. | true | boolean |
keyAttributeName (producer) | Attribute name when creating table. | String | |
keyAttributeType (producer) | Attribute type when creating table. | String | |
keyScalarType (producer) | The key scalar type, it can be S (String), N (Number) and B (Bytes). | 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 |
operation (producer) | What operation to perform. Enum values:
| PutItem | Ddb2Operations |
overrideEndpoint (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
proxyHost (producer) | To define a proxy host when instantiating the DDB client. | String | |
proxyPort (producer) | The region in which DynamoDB client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | Integer | |
proxyProtocol (producer) | To define a proxy protocol when instantiating the DDB client. Enum values:
| HTTPS | Protocol |
readCapacity (producer) | The provisioned throughput to reserve for reading resources from your table. | Long | |
region (producer) | The region in which DDB client needs to work. | String | |
trustAllCertificates (producer) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (producer) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (producer) | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
writeCapacity (producer) | The provisioned throughput to reserved for writing resources to your table. | Long | |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
Required DDB component options
You have to provide the amazonDDBClient in the Registry or your accessKey and secretKey to access the Amazon’s DynamoDB.
2.5. Usage
2.5.1. Static credentials vs Default Credential Provider
You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.
- Java system properties - aws.accessKeyId and aws.secretKey
- Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
- Web Identity Token from AWS STS.
- The shared credentials and config files.
- Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
- Amazon EC2 Instance profile credentials.
For more information about this you can look at AWS credentials documentation
2.5.2. Message headers evaluated by the DDB producer
Header | Type | Description |
---|---|---|
|
| A map of the table name and corresponding items to get by primary key. |
|
| Table Name for this operation. |
|
| The primary key that uniquely identifies each item in a table. |
|
| Use this parameter if you want to get the attribute name-value pairs before or after they are modified(NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW). |
|
| Designates an attribute for a conditional modification. |
|
| If attribute names are not specified then all attributes will be returned. |
|
| If set to true, then a consistent read is issued, otherwise eventually consistent is used. |
|
| If set will be used as Secondary Index for Query operation. |
|
| A map of the attributes for the item, and must include the primary key values that define the item. |
|
| If set to true, Amazon DynamoDB returns a total number of items that match the query parameters, instead of a list of the matching items and their attributes. |
|
| This header specify the selection criteria for the query, and merge together the two old headers CamelAwsDdbHashKeyValue and CamelAwsDdbScanRangeKeyCondition |
|
| Primary key of the item from which to continue an earlier query. |
|
| Value of the hash component of the composite primary key. |
|
| The maximum number of items to return. |
|
| A container for the attribute values and comparison operators to use for the query. |
|
| Specifies forward or backward traversal of the index. |
|
| Evaluates the scan results and returns only the desired values. |
|
| Map of attribute name to the new value and action for the update. |
2.5.3. Message headers set during BatchGetItems operation
Header | Type | Description |
---|---|---|
|
| Table names and the respective item attributes from the tables. |
|
| Contains a map of tables and their respective keys that were not processed with the current response. |
2.5.4. Message headers set during DeleteItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
2.5.5. Message headers set during DeleteTable operation
Header | Type | Description |
---|---|---|
| ||
| The value of the ProvisionedThroughput property for this table | |
|
| Creation DateTime of this table. |
|
| Item count for this table. |
|
| The KeySchema that identifies the primary key for this table. From Camel 2.16.0 the type of this header is List<KeySchemaElement> and not KeySchema |
|
| The table name. |
|
| The table size in bytes. |
|
| The status of the table: CREATING, UPDATING, DELETING, ACTIVE |
2.5.6. Message headers set during DescribeTable operation
Header | Type | Description |
---|---|---|
| \{{ProvisionedThroughputDescription}} | The value of the ProvisionedThroughput property for this table |
|
| Creation DateTime of this table. |
|
| Item count for this table. |
| \{{KeySchema}} | The KeySchema that identifies the primary key for this table. |
|
| The table name. |
|
| The table size in bytes. |
|
| The status of the table: CREATING, UPDATING, DELETING, ACTIVE |
|
| ReadCapacityUnits property of this table. |
|
| WriteCapacityUnits property of this table. |
2.5.7. Message headers set during GetItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
2.5.8. Message headers set during PutItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
2.5.9. Message headers set during Query operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
|
| Primary key of the item where the query operation stopped, inclusive of the previous result set. |
|
| The number of Capacity Units of the provisioned throughput of the table consumed during the operation. |
|
| Number of items in the response. |
2.5.10. Message headers set during Scan operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
|
| Primary key of the item where the query operation stopped, inclusive of the previous result set. |
|
| The number of Capacity Units of the provisioned throughput of the table consumed during the operation. |
|
| Number of items in the response. |
|
| Number of items in the complete scan before any filters are applied. |
2.5.11. Message headers set during UpdateItem operation
Header | Type | Description |
---|---|---|
|
| The list of attributes returned by the operation. |
2.5.12. Advanced AmazonDynamoDB configuration
If you need more control over the AmazonDynamoDB
instance configuration you can create your own instance and refer to it from the URI:
from("direct:start") .to("aws2-ddb://domainName?amazonDDBClient=#client");
The #client
refers to a DynamoDbClient
in the Registry.
2.6. Supported producer operations
- BatchGetItems
- DeleteItem
- DeleteTable
- DescribeTable
- GetItem
- PutItem
- Query
- Scan
- UpdateItem
- UpdateTable
2.7. Examples
2.7.1. Producer Examples
- PutItem: this operation will create an entry into DynamoDB
from("direct:start") .setHeader(Ddb2Constants.OPERATION, Ddb2Operations.PutItem) .setHeader(Ddb2Constants.CONSISTENT_READ, "true") .setHeader(Ddb2Constants.RETURN_VALUES, "ALL_OLD") .setHeader(Ddb2Constants.ITEM, attributeMap) .setHeader(Ddb2Constants.ATTRIBUTE_NAMES, attributeMap.keySet()); .to("aws2-ddb://" + tableName + "?keyAttributeName=" + attributeName + "&keyAttributeType=" + KeyType.HASH + "&keyScalarType=" + ScalarAttributeType.S + "&readCapacity=1&writeCapacity=1");
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws2-ddb</artifactId> <version>${camel-version}</version> </dependency>
where 3.14.2
must be replaced by the actual version of Camel.
2.8. Spring Boot Auto-Configuration
When using aws2-ddb with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-aws2-ddb-starter</artifactId> <version>{CamelSBProjectVersion}</version> <!-- Use your Camel Spring Boot version --> </dependency>
The component supports 40 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws2-ddb.access-key | Amazon AWS Access Key. | String | |
camel.component.aws2-ddb.amazon-d-d-b-client | To use the AmazonDynamoDB as the client. The option is a software.amazon.awssdk.services.dynamodb.DynamoDbClient type. | DynamoDbClient | |
camel.component.aws2-ddb.autowired-enabled | 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 |
camel.component.aws2-ddb.configuration | The component configuration. The option is a org.apache.camel.component.aws2.ddb.Ddb2Configuration type. | Ddb2Configuration | |
camel.component.aws2-ddb.consistent-read | Determines whether or not strong consistency should be enforced when data is read. | false | Boolean |
camel.component.aws2-ddb.enabled | Whether to enable auto configuration of the aws2-ddb component. This is enabled by default. | Boolean | |
camel.component.aws2-ddb.enabled-initial-describe-table | Set whether the initial Describe table operation in the DDB Endpoint must be done, or not. | true | Boolean |
camel.component.aws2-ddb.key-attribute-name | Attribute name when creating table. | String | |
camel.component.aws2-ddb.key-attribute-type | Attribute type when creating table. | String | |
camel.component.aws2-ddb.key-scalar-type | The key scalar type, it can be S (String), N (Number) and B (Bytes). | String | |
camel.component.aws2-ddb.lazy-start-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 |
camel.component.aws2-ddb.operation | What operation to perform. | Ddb2Operations | |
camel.component.aws2-ddb.override-endpoint | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | Boolean |
camel.component.aws2-ddb.proxy-host | To define a proxy host when instantiating the DDB client. | String | |
camel.component.aws2-ddb.proxy-port | The region in which DynamoDB client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | Integer | |
camel.component.aws2-ddb.proxy-protocol | To define a proxy protocol when instantiating the DDB client. | Protocol | |
camel.component.aws2-ddb.read-capacity | The provisioned throughput to reserve for reading resources from your table. | Long | |
camel.component.aws2-ddb.region | The region in which DDB client needs to work. | String | |
camel.component.aws2-ddb.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws2-ddb.trust-all-certificates | If we want to trust all certificates in case of overriding the endpoint. | false | Boolean |
camel.component.aws2-ddb.uri-endpoint-override | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
camel.component.aws2-ddb.use-default-credentials-provider | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | Boolean |
camel.component.aws2-ddb.write-capacity | The provisioned throughput to reserved for writing resources to your table. | Long | |
camel.component.aws2-ddbstream.access-key | Amazon AWS Access Key. | String | |
camel.component.aws2-ddbstream.amazon-dynamo-db-streams-client | Amazon DynamoDB client to use for all requests for this endpoint. The option is a software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient type. | DynamoDbStreamsClient | |
camel.component.aws2-ddbstream.autowired-enabled | 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 |
camel.component.aws2-ddbstream.bridge-error-handler | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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 |
camel.component.aws2-ddbstream.configuration | The component configuration. The option is a org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration type. | Ddb2StreamConfiguration | |
camel.component.aws2-ddbstream.enabled | Whether to enable auto configuration of the aws2-ddbstream component. This is enabled by default. | Boolean | |
camel.component.aws2-ddbstream.max-results-per-request | Maximum number of records that will be fetched in each poll. | Integer | |
camel.component.aws2-ddbstream.override-endpoint | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | Boolean |
camel.component.aws2-ddbstream.proxy-host | To define a proxy host when instantiating the DDBStreams client. | String | |
camel.component.aws2-ddbstream.proxy-port | To define a proxy port when instantiating the DDBStreams client. | Integer | |
camel.component.aws2-ddbstream.proxy-protocol | To define a proxy protocol when instantiating the DDBStreams client. | Protocol | |
camel.component.aws2-ddbstream.region | The region in which DDBStreams client needs to work. | String | |
camel.component.aws2-ddbstream.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws2-ddbstream.stream-iterator-type | Defines where in the DynamoDB stream to start getting records. Note that using FROM_START can cause a significant delay before the stream has caught up to real-time. | Ddb2StreamConfiguration$StreamIteratorType | |
camel.component.aws2-ddbstream.trust-all-certificates | If we want to trust all certificates in case of overriding the endpoint. | false | Boolean |
camel.component.aws2-ddbstream.uri-endpoint-override | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
camel.component.aws2-ddbstream.use-default-credentials-provider | Set whether the DynamoDB Streams client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | Boolean |
Chapter 3. AWS Kinesis
Both producer and consumer are supported
The AWS2 Kinesis component supports receiving messages from and sending messages to Amazon Kinesis (no Batch supported) service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Kinesis. More information are available at AWS Kinesis.
3.1. URI Format
aws2-kinesis://stream-name[?options]
The stream needs to be created prior to it being used. You can append query options to the URI in the following format, ?options=value&option2=value&…
3.2. Configuring Options
Camel components are configured on two separate levels:
- component level
- endpoint level
3.2.1. Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
3.2.2. Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
3.3. Component Options
The AWS Kinesis component supports 22 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
amazonKinesisClient (common) | Autowired Amazon Kinesis client to use for all requests for this endpoint. | KinesisClient | |
cborEnabled (common) | This option will set the CBOR_ENABLED property during the execution. | true | boolean |
configuration (common) | Component configuration. | Kinesis2Configuration | |
overrideEndpoint (common) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
proxyHost (common) | To define a proxy host when instantiating the Kinesis client. | String | |
proxyPort (common) | To define a proxy port when instantiating the Kinesis client. | Integer | |
proxyProtocol (common) | To define a proxy protocol when instantiating the Kinesis client. Enum values:
| HTTPS | Protocol |
region (common) | The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
trustAllCertificates (common) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (common) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (common) | Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
bridgeErrorHandler (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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 |
iteratorType (consumer) | Defines where in the Kinesis stream to start getting records. Enum values:
| TRIM_HORIZON | ShardIteratorType |
maxResultsPerRequest (consumer) | Maximum number of records that will be fetched in each poll. | 1 | int |
resumeStrategy (consumer) | Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided. | KinesisUserConfigurationResumeStrategy | KinesisResumeStrategy |
sequenceNumber (consumer) | The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER. | String | |
shardClosed (consumer) | Define what will be the behavior in case of shard closed. Possible value are ignore, silent and fail. In case of ignore a message will be logged and the consumer will restart from the beginning,in case of silent there will be no logging and the consumer will start from the beginning,in case of fail a ReachedClosedStateException will be raised. Enum values:
| ignore | Kinesis2ShardClosedStrategyEnum |
shardId (consumer) | Defines which shardId in the Kinesis stream to get records from. | 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 |
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 |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
3.4. Endpoint Options
The AWS Kinesis endpoint is configured using URI syntax:
aws2-kinesis:streamName
with the following path and query parameters:
3.4.1. Path Parameters (1 parameters)
Name | Description | Default | Type |
---|---|---|---|
streamName (common) | Required Name of the stream. | String |
3.4.2. Query Parameters (38 parameters)
Name | Description | Default | Type |
---|---|---|---|
amazonKinesisClient (common) | Autowired Amazon Kinesis client to use for all requests for this endpoint. | KinesisClient | |
cborEnabled (common) | This option will set the CBOR_ENABLED property during the execution. | true | boolean |
overrideEndpoint (common) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
proxyHost (common) | To define a proxy host when instantiating the Kinesis client. | String | |
proxyPort (common) | To define a proxy port when instantiating the Kinesis client. | Integer | |
proxyProtocol (common) | To define a proxy protocol when instantiating the Kinesis client. Enum values:
| HTTPS | Protocol |
region (common) | The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
trustAllCertificates (common) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (common) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (common) | Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
bridgeErrorHandler (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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 |
iteratorType (consumer) | Defines where in the Kinesis stream to start getting records. Enum values:
| TRIM_HORIZON | ShardIteratorType |
maxResultsPerRequest (consumer) | Maximum number of records that will be fetched in each poll. | 1 | int |
resumeStrategy (consumer) | Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided. | KinesisUserConfigurationResumeStrategy | KinesisResumeStrategy |
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 |
sequenceNumber (consumer) | The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER. | String | |
shardClosed (consumer) | Define what will be the behavior in case of shard closed. Possible value are ignore, silent and fail. In case of ignore a message will be logged and the consumer will restart from the beginning,in case of silent there will be no logging and the consumer will start from the beginning,in case of fail a ReachedClosedStateException will be raised. Enum values:
| ignore | Kinesis2ShardClosedStrategyEnum |
shardId (consumer) | Defines which shardId in the Kinesis stream to get records from. | String | |
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:
| 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 | |
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 |
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 |
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 | 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. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
Required Kinesis component options
You have to provide the KinesisClient in the Registry with proxies and relevant credentials configured.
3.5. Batch Consumer
This component implements the Batch Consumer.
This allows you for instance to know how many messages exists in this batch and for instance let the Aggregator aggregate this number of messages.
3.6. Usage
3.6.1. Static credentials vs Default Credential Provider
You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.
- Java system properties - aws.accessKeyId and aws.secretKey
- Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
- Web Identity Token from AWS STS.
- The shared credentials and config files.
- Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
- Amazon EC2 Instance profile credentials.
For more information about this you can look at AWS credentials documentation
3.6.2. Message headers set by the Kinesis consumer
Header | Type | Description |
---|---|---|
|
| The sequence number of the record. This is represented as a String as it size is not defined by the API. If it is to be used as a numerical type then use |
|
| The time AWS assigned as the arrival time of the record. |
|
| Identifies which shard in the stream the data record is assigned to. |
3.6.3. AmazonKinesis configuration
You then have to reference the KinesisClient in the amazonKinesisClient
URI option.
from("aws2-kinesis://mykinesisstream?amazonKinesisClient=#kinesisClient") .to("log:out?showAll=true");
3.6.4. Providing AWS Credentials
It is recommended that the credentials are obtained by using the DefaultAWSCredentialsProviderChain that is the default when creating a new ClientConfiguration instance, however, a different AWSCredentialsProvider can be specified when calling createClient(…).
3.6.5. Message headers used by the Kinesis producer to write to Kinesis. The producer expects that the message body is a byte[]
.
Header | Type | Description |
---|---|---|
|
| The PartitionKey to pass to Kinesis to store this record. |
|
| Optional paramter to indicate the sequence number of this record. |
3.6.6. Message headers set by the Kinesis producer on successful storage of a Record
Header | Type | Description |
---|---|---|
|
| The sequence number of the record, as defined in Response Syntax |
|
| The shard ID of where the Record was stored |
3.7. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws2-kinesis</artifactId> <version>${camel-version}</version> </dependency>
where 3.14.2
must be replaced by the actual version of Camel.
3.8. Spring Boot Auto-Configuration
When using aws2-kinesis with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-aws2-kinesis-starter</artifactId> <version>{CamelSBProjectVersion}</version> <!-- use your Camel Spring Boot version --> </dependency>
The component supports 40 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws2-kinesis-firehose.access-key | Amazon AWS Access Key. | String | |
camel.component.aws2-kinesis-firehose.amazon-kinesis-firehose-client | Amazon Kinesis Firehose client to use for all requests for this endpoint. The option is a software.amazon.awssdk.services.firehose.FirehoseClient type. | FirehoseClient | |
camel.component.aws2-kinesis-firehose.autowired-enabled | 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 |
camel.component.aws2-kinesis-firehose.cbor-enabled | This option will set the CBOR_ENABLED property during the execution. | true | Boolean |
camel.component.aws2-kinesis-firehose.configuration | Component configuration. The option is a org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration type. | KinesisFirehose2Configuration | |
camel.component.aws2-kinesis-firehose.enabled | Whether to enable auto configuration of the aws2-kinesis-firehose component. This is enabled by default. | Boolean | |
camel.component.aws2-kinesis-firehose.lazy-start-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 |
camel.component.aws2-kinesis-firehose.operation | The operation to do in case the user don’t want to send only a record. | KinesisFirehose2Operations | |
camel.component.aws2-kinesis-firehose.override-endpoint | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | Boolean |
camel.component.aws2-kinesis-firehose.proxy-host | To define a proxy host when instantiating the Kinesis Firehose client. | String | |
camel.component.aws2-kinesis-firehose.proxy-port | To define a proxy port when instantiating the Kinesis Firehose client. | Integer | |
camel.component.aws2-kinesis-firehose.proxy-protocol | To define a proxy protocol when instantiating the Kinesis Firehose client. | Protocol | |
camel.component.aws2-kinesis-firehose.region | The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
camel.component.aws2-kinesis-firehose.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws2-kinesis-firehose.trust-all-certificates | If we want to trust all certificates in case of overriding the endpoint. | false | Boolean |
camel.component.aws2-kinesis-firehose.uri-endpoint-override | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
camel.component.aws2-kinesis-firehose.use-default-credentials-provider | Set whether the Kinesis Firehose client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | Boolean |
camel.component.aws2-kinesis.access-key | Amazon AWS Access Key. | String | |
camel.component.aws2-kinesis.amazon-kinesis-client | Amazon Kinesis client to use for all requests for this endpoint. The option is a software.amazon.awssdk.services.kinesis.KinesisClient type. | KinesisClient | |
camel.component.aws2-kinesis.autowired-enabled | 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 |
camel.component.aws2-kinesis.bridge-error-handler | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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 |
camel.component.aws2-kinesis.cbor-enabled | This option will set the CBOR_ENABLED property during the execution. | true | Boolean |
camel.component.aws2-kinesis.configuration | Component configuration. The option is a org.apache.camel.component.aws2.kinesis.Kinesis2Configuration type. | Kinesis2Configuration | |
camel.component.aws2-kinesis.enabled | Whether to enable auto configuration of the aws2-kinesis component. This is enabled by default. | Boolean | |
camel.component.aws2-kinesis.iterator-type | Defines where in the Kinesis stream to start getting records. | ShardIteratorType | |
camel.component.aws2-kinesis.lazy-start-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 |
camel.component.aws2-kinesis.max-results-per-request | Maximum number of records that will be fetched in each poll. | 1 | Integer |
camel.component.aws2-kinesis.override-endpoint | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | Boolean |
camel.component.aws2-kinesis.proxy-host | To define a proxy host when instantiating the Kinesis client. | String | |
camel.component.aws2-kinesis.proxy-port | To define a proxy port when instantiating the Kinesis client. | Integer | |
camel.component.aws2-kinesis.proxy-protocol | To define a proxy protocol when instantiating the Kinesis client. | Protocol | |
camel.component.aws2-kinesis.region | The region in which Kinesis Firehose client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
camel.component.aws2-kinesis.resume-strategy | Defines a resume strategy for AWS Kinesis. The default strategy reads the sequenceNumber if provided. The option is a org.apache.camel.component.aws2.kinesis.consumer.KinesisResumeStrategy type. | KinesisResumeStrategy | |
camel.component.aws2-kinesis.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws2-kinesis.sequence-number | The sequence number to start polling from. Required if iteratorType is set to AFTER_SEQUENCE_NUMBER or AT_SEQUENCE_NUMBER. | String | |
camel.component.aws2-kinesis.shard-closed | Define what will be the behavior in case of shard closed. Possible value are ignore, silent and fail. In case of ignore a message will be logged and the consumer will restart from the beginning,in case of silent there will be no logging and the consumer will start from the beginning,in case of fail a ReachedClosedStateException will be raised. | Kinesis2ShardClosedStrategyEnum | |
camel.component.aws2-kinesis.shard-id | Defines which shardId in the Kinesis stream to get records from. | String | |
camel.component.aws2-kinesis.trust-all-certificates | If we want to trust all certificates in case of overriding the endpoint. | false | Boolean |
camel.component.aws2-kinesis.uri-endpoint-override | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
camel.component.aws2-kinesis.use-default-credentials-provider | Set whether the Kinesis client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | Boolean |
Chapter 4. AWS 2 Lambda
Only producer is supported
The AWS2 Lambda component supports create, get, list, delete and invoke AWS Lambda functions.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Lambda. More information is available at AWS Lambda.
When creating a Lambda function, you need to specify a IAM role which has at least the AWSLambdaBasicExecuteRole policy attached.
4.1. URI Format
aws2-lambda://functionName[?options]
You can append query options to the URI in the following format, options=value&option2=value&…
4.2. Configuring Options
Camel components are configured on two separate levels:
- component level
- endpoint level
4.2.1. Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
4.2.2. Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
4.3. Component Options
The AWS Lambda component supports 16 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
configuration (producer) | Component configuration. | Lambda2Configuration | |
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 |
operation (producer) | The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction. Enum values:
| invokeFunction | Lambda2Operations |
overrideEndpoint (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
pojoRequest (producer) | If we want to use a POJO request as body or not. | false | boolean |
region (producer) | The region in which Lambda client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
trustAllCertificates (producer) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (producer) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (producer) | Set whether the Lambda client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | 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 |
awsLambdaClient (advanced) | Autowired To use a existing configured AwsLambdaClient as client. | LambdaClient | |
proxyHost (proxy) | To define a proxy host when instantiating the Lambda client. | String | |
proxyPort (proxy) | To define a proxy port when instantiating the Lambda client. | Integer | |
proxyProtocol (proxy) | To define a proxy protocol when instantiating the Lambda client. Enum values:
| HTTPS | Protocol |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
4.4. Endpoint Options
The AWS Lambda endpoint is configured using URI syntax:
aws2-lambda:function
with the following path and query parameters:
4.4.1. Path Parameters (1 parameters)
Name | Description | Default | Type |
---|---|---|---|
function (producer) | Required Name of the Lambda function. | String |
4.4.2. Query Parameters (14 parameters)
Name | Description | Default | Type |
---|---|---|---|
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 |
operation (producer) | The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction. Enum values:
| invokeFunction | Lambda2Operations |
overrideEndpoint (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
pojoRequest (producer) | If we want to use a POJO request as body or not. | false | boolean |
region (producer) | The region in which Lambda client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
trustAllCertificates (producer) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (producer) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (producer) | Set whether the Lambda client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
awsLambdaClient (advanced) | Autowired To use a existing configured AwsLambdaClient as client. | LambdaClient | |
proxyHost (proxy) | To define a proxy host when instantiating the Lambda client. | String | |
proxyPort (proxy) | To define a proxy port when instantiating the Lambda client. | Integer | |
proxyProtocol (proxy) | To define a proxy protocol when instantiating the Lambda client. Enum values:
| HTTPS | Protocol |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
Required Lambda component options
You have to provide the awsLambdaClient in the Registry or your accessKey and secretKey to access the Amazon Lambda service..
4.5. Usage
4.5.1. Static credentials vs Default Credential Provider
You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true.
- Java system properties - aws.accessKeyId and aws.secretKey
- Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
- Web Identity Token from AWS STS.
- The shared credentials and config files.
- Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set.
- Amazon EC2 Instance profile credentials.
For more information about this you can look at AWS credentials documentation
4.5.2. Message headers evaluated by the Lambda producer
Operation | Header | Type | Description | Required |
---|---|---|---|---|
All |
|
| The operation we want to perform. Override operation passed as query parameter | Yes |
createFunction |
|
| Amazon S3 bucket name where the .zip file containing your deployment package is stored. This bucket must reside in the same AWS region where you are creating the Lambda function. | No |
createFunction |
|
| The Amazon S3 object (the deployment package) key name you want to upload. | No |
createFunction |
| String | The Amazon S3 object (the deployment package) version you want to upload. | No |
createFunction |
|
| The local path of the zip file (the deployment package). Content of zip file can also be put in Message body. | No |
createFunction |
|
| The Amazon Resource Name (ARN) of the IAM role that Lambda assumes when it executes your function to access any other Amazon Web Services (AWS) resources. | Yes |
createFunction |
| String | The runtime environment for the Lambda function you are uploading. (nodejs, nodejs4.3, nodejs6.10, java8, python2.7, python3.6, dotnetcore1.0, odejs4.3-edge) | Yes |
createFunction |
|
| The function within your code that Lambda calls to begin execution. For Node.js, it is the module-name.export value in your function. For Java, it can be package.class-name::handler or package.class-name. | Yes |
createFunction |
|
| The user-provided description. | No |
createFunction |
|
| The parent object that contains the target ARN (Amazon Resource Name) of an Amazon SQS queue or Amazon SNS topic. | No |
createFunction |
|
| The memory size, in MB, you configured for the function. Must be a multiple of 64 MB. | No |
createFunction |
|
| The Amazon Resource Name (ARN) of the KMS key used to encrypt your function’s environment variables. If not provided, AWS Lambda will use a default service key. | No |
createFunction |
|
| This boolean parameter can be used to request AWS Lambda to create the Lambda function and publish a version as an atomic operation. | No |
createFunction |
|
| The function execution time at which Lambda should terminate the function. The default is 3 seconds. | No |
createFunction |
|
| Your function’s tracing settings (Active or PassThrough). | No |
createFunction |
|
| The key-value pairs that represent your environment’s configuration settings. | No |
createFunction |
|
| The list of tags (key-value pairs) assigned to the new function. | No |
createFunction |
|
| If your Lambda function accesses resources in a VPC, a list of one or more security groups IDs in your VPC. | No |
createFunction |
|
| If your Lambda function accesses resources in a VPC, a list of one or more subnet IDs in your VPC. | No |
createAlias |
|
| The function version to set in the alias | Yes |
createAlias |
|
| The function name to set in the alias | Yes |
createAlias |
|
| The function description to set in the alias | No |
deleteAlias |
|
| The function name of the alias | Yes |
getAlias |
|
| The function name of the alias | Yes |
listAliases |
|
| The function version to set in the alias | No |
4.6. List of Avalaible Operations
- listFunctions
- getFunction
- createFunction
- deleteFunction
- invokeFunction
- updateFunction
- createEventSourceMapping
- deleteEventSourceMapping
- listEventSourceMapping
- listTags
- tagResource
- untagResource
- publishVersion
- listVersions
- createAlias
- deleteAlias
- getAlias
- listAliases
4.7. Examples
4.7.1. Producer Example
To have a full understanding of how the component works, you may have a look at these integration tests.
4.7.2. Producer Examples
- CreateFunction: this operation will create a function for you in AWS Lambda
from("direct:createFunction").to("aws2-lambda://GetHelloWithName?operation=createFunction").to("mock:result");
and by sending
template.send("direct:createFunction", ExchangePattern.InOut, new Processor() { @Override public void process(Exchange exchange) throws Exception { exchange.getIn().setHeader(Lambda2Constants.RUNTIME, "nodejs6.10"); exchange.getIn().setHeader(Lambda2Constants.HANDLER, "GetHelloWithName.handler"); exchange.getIn().setHeader(Lambda2Constants.DESCRIPTION, "Hello with node.js on Lambda"); exchange.getIn().setHeader(Lambda2Constants.ROLE, "arn:aws:iam::643534317684:role/lambda-execution-role"); ClassLoader classLoader = getClass().getClassLoader(); File file = new File( classLoader .getResource("org/apache/camel/component/aws2/lambda/function/node/GetHelloWithName.zip") .getFile()); FileInputStream inputStream = new FileInputStream(file); exchange.getIn().setBody(inputStream); } });
4.8. Using a POJO as body
Sometimes build an AWS Request can be complex, because of multiple options. We introduce the possibility to use a POJO as body. In AWS Lambda there are multiple operations you can submit, as an example for Get Function request, you can do something like:
from("direct:getFunction") .setBody(GetFunctionRequest.builder().functionName("test").build()) .to("aws2-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=getFunction&pojoRequest=true")
In this way you’ll pass the request directly without the need of passing headers and options specifically related to this operation.
4.9. Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws2-lambda</artifactId> <version>${camel-version}</version> </dependency>
where 3.14.2
must be replaced by the actual version of Camel.
4.10. Spring Boot Auto-Configuration
When using aws2-lambda with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-aws2-lambda-starter</artifactId> <version>{CamelSBProjectVersion}</version> <!-- use your Camel Spring Boot version --> </dependency>
The component supports 17 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.aws2-lambda.access-key | Amazon AWS Access Key. | String | |
camel.component.aws2-lambda.autowired-enabled | 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 |
camel.component.aws2-lambda.aws-lambda-client | To use a existing configured AwsLambdaClient as client. The option is a software.amazon.awssdk.services.lambda.LambdaClient type. | LambdaClient | |
camel.component.aws2-lambda.configuration | Component configuration. The option is a org.apache.camel.component.aws2.lambda.Lambda2Configuration type. | Lambda2Configuration | |
camel.component.aws2-lambda.enabled | Whether to enable auto configuration of the aws2-lambda component. This is enabled by default. | Boolean | |
camel.component.aws2-lambda.lazy-start-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 |
camel.component.aws2-lambda.operation | The operation to perform. It can be listFunctions, getFunction, createFunction, deleteFunction or invokeFunction. | Lambda2Operations | |
camel.component.aws2-lambda.override-endpoint | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | Boolean |
camel.component.aws2-lambda.pojo-request | If we want to use a POJO request as body or not. | false | Boolean |
camel.component.aws2-lambda.proxy-host | To define a proxy host when instantiating the Lambda client. | String | |
camel.component.aws2-lambda.proxy-port | To define a proxy port when instantiating the Lambda client. | Integer | |
camel.component.aws2-lambda.proxy-protocol | To define a proxy protocol when instantiating the Lambda client. | Protocol | |
camel.component.aws2-lambda.region | The region in which Lambda client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
camel.component.aws2-lambda.secret-key | Amazon AWS Secret Key. | String | |
camel.component.aws2-lambda.trust-all-certificates | If we want to trust all certificates in case of overriding the endpoint. | false | Boolean |
camel.component.aws2-lambda.uri-endpoint-override | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
camel.component.aws2-lambda.use-default-credentials-provider | Set whether the Lambda client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | Boolean |
Chapter 5. AWS S3 Storage Service
Both producer and consumer are supported
The AWS2 S3 component supports storing and retrieving objects from/to Amazon’s S3 service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon S3. More information is available at link:https://aws.amazon.com/s3 [Amazon S3].
5.1. URI Format
aws2-s3://bucketNameOrArn[?options]
The bucket will be created if it don’t already exists. You can append query options to the URI in the following format,
options=value&option2=value&…
5.2. Configuring Options
Camel components are configured on two separate levels:
- component level
- endpoint level
5.2.1. Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
5.2.2. Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
5.3. Component Options
The AWS S3 Storage Service component supports 50 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
amazonS3Client (common) | Autowired Reference to a com.amazonaws.services.s3.AmazonS3 in the registry. | S3Client | |
amazonS3Presigner (common) | Autowired An S3 Presigner for Request, used mainly in createDownloadLink operation. | S3Presigner | |
autoCreateBucket (common) | Setting the autocreation of the S3 bucket bucketName. This will apply also in case of moveAfterRead option enabled and it will create the destinationBucket if it doesn’t exist already. | false | boolean |
configuration (common) | The component configuration. | AWS2S3Configuration | |
overrideEndpoint (common) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
pojoRequest (common) | If we want to use a POJO request as body or not. | false | boolean |
policy (common) | The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method. | String | |
proxyHost (common) | To define a proxy host when instantiating the SQS client. | String | |
proxyPort (common) | Specify a proxy port to be used inside the client definition. | Integer | |
proxyProtocol (common) | To define a proxy protocol when instantiating the S3 client. Enum values:
| HTTPS | Protocol |
region (common) | The region in which S3 client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
trustAllCertificates (common) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (common) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (common) | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
customerAlgorithm (common (advanced)) | Define the customer algorithm to use in case CustomerKey is enabled. | String | |
customerKeyId (common (advanced)) | Define the id of Customer key to use in case CustomerKey is enabled. | String | |
customerKeyMD5 (common (advanced)) | Define the MD5 of Customer key to use in case CustomerKey is enabled. | String | |
bridgeErrorHandler (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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) | Delete objects from S3 after they have been retrieved. The delete is only performed if the Exchange is committed. If a rollback occurs, the object is not deleted. If this option is false, then the same objects will be retrieve over and over again on the polls. Therefore you need to use the Idempotent Consumer EIP in the route to filter out duplicates. You can filter using the AWS2S3Constants#BUCKET_NAME and AWS2S3Constants#KEY headers, or only the AWS2S3Constants#KEY header. | true | boolean |
delimiter (consumer) | The delimiter which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in. | String | |
destinationBucket (consumer) | Define the destination bucket where an object must be moved when moveAfterRead is set to true. | String | |
destinationBucketPrefix (consumer) | Define the destination bucket prefix to use when an object must be moved and moveAfterRead is set to true. | String | |
destinationBucketSuffix (consumer) | Define the destination bucket suffix to use when an object must be moved and moveAfterRead is set to true. | String | |
doneFileName (consumer) | If provided, Camel will only consume files if a done file exists. | String | |
fileName (consumer) | To get the object from the bucket with the given file name. | String | |
ignoreBody (consumer) | If it is true, the S3 Object Body will be ignored completely, if it is set to false the S3 Object will be put in the body. Setting this to true, will override any behavior defined by includeBody option. | false | boolean |
includeBody (consumer) | If it is true, the S3Object exchange will be consumed and put into the body and closed. If false the S3Object stream will be put raw into the body and the headers will be set with the S3 object metadata. This option is strongly related to autocloseBody option. In case of setting includeBody to true because the S3Object stream will be consumed then it will also be closed, while in case of includeBody false then it will be up to the caller to close the S3Object stream. However setting autocloseBody to true when includeBody is false it will schedule to close the S3Object stream automatically on exchange completion. | true | boolean |
includeFolders (consumer) | If it is true, the folders/directories will be consumed. If it is false, they will be ignored, and Exchanges will not be created for those. | true | boolean |
moveAfterRead (consumer) | Move objects from S3 bucket to a different bucket after they have been retrieved. To accomplish the operation the destinationBucket option must be set. The copy bucket operation is only performed if the Exchange is committed. If a rollback occurs, the object is not moved. | false | boolean |
prefix (consumer) | The prefix which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in. | String | |
autocloseBody (consumer (advanced)) | If this option is true and includeBody is false, then the S3Object.close() method will be called on exchange completion. This option is strongly related to includeBody option. In case of setting includeBody to false and autocloseBody to false, it will be up to the caller to close the S3Object stream. Setting autocloseBody to true, will close the S3Object stream automatically. | true | boolean |
batchMessageNumber (producer) | The number of messages composing a batch in streaming upload mode. | 10 | int |
batchSize (producer) | The batch size (in bytes) in streaming upload mode. | 1000000 | int |
deleteAfterWrite (producer) | Delete file object after the S3 file has been uploaded. | false | boolean |
keyName (producer) | Setting the key name for an element in the bucket through endpoint parameter. | 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) | If it is true, camel will upload the file with multi part format, the part size is decided by the option of partSize. | false | boolean |
namingStrategy (producer) | The naming strategy to use in streaming upload mode. Enum values:
| progressive | AWSS3NamingStrategyEnum |
operation (producer) | The operation to do in case the user don’t want to do only an upload. Enum values:
| AWS2S3Operations | |
partSize (producer) | Setup the partSize which is used in multi part upload, the default size is 25M. | 26214400 | long |
restartingPolicy (producer) | The restarting policy to use in streaming upload mode. Enum values:
| override | AWSS3RestartingPolicyEnum |
storageClass (producer) | The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request. | String | |
streamingUploadMode (producer) | When stream mode is true the upload to bucket will be done in streaming. | false | boolean |
streamingUploadTimeout (producer) | While streaming upload mode is true, this option set the timeout to complete upload. | long | |
awsKMSKeyId (producer (advanced)) | Define the id of KMS key to use in case KMS is enabled. | String | |
useAwsKMS (producer (advanced)) | Define if KMS must be used or not. | false | boolean |
useCustomerKey (producer (advanced)) | Define if Customer Key must be used or not. | 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 |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
5.4. Endpoint Options
The AWS S3 Storage Service endpoint is configured using URI syntax:
aws2-s3://bucketNameOrArn
with the following path and query parameters:
5.4.1. Path Parameters (1 parameters)
Name | Description | Default | Type |
---|---|---|---|
bucketNameOrArn (common) | Required Bucket name or ARN. | String |
5.4.2. Query Parameters (68 parameters)
Name | Description | Default | Type |
---|---|---|---|
amazonS3Client (common) | Autowired Reference to a com.amazonaws.services.s3.AmazonS3 in the registry. | S3Client | |
amazonS3Presigner (common) | Autowired An S3 Presigner for Request, used mainly in createDownloadLink operation. | S3Presigner | |
autoCreateBucket (common) | Setting the autocreation of the S3 bucket bucketName. This will apply also in case of moveAfterRead option enabled and it will create the destinationBucket if it doesn’t exist already. | false | boolean |
overrideEndpoint (common) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option. | false | boolean |
pojoRequest (common) | If we want to use a POJO request as body or not. | false | boolean |
policy (common) | The policy for this queue to set in the com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method. | String | |
proxyHost (common) | To define a proxy host when instantiating the SQS client. | String | |
proxyPort (common) | Specify a proxy port to be used inside the client definition. | Integer | |
proxyProtocol (common) | To define a proxy protocol when instantiating the S3 client. Enum values:
| HTTPS | Protocol |
region (common) | The region in which S3 client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). | String | |
trustAllCertificates (common) | If we want to trust all certificates in case of overriding the endpoint. | false | boolean |
uriEndpointOverride (common) | Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | |
useDefaultCredentialsProvider (common) | Set whether the S3 client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean |
customerAlgorithm (common (advanced)) | Define the customer algorithm to use in case CustomerKey is enabled. | String | |
customerKeyId (common (advanced)) | Define the id of Customer key to use in case CustomerKey is enabled. | String | |
customerKeyMD5 (common (advanced)) | Define the MD5 of Customer key to use in case CustomerKey is enabled. | String | |
bridgeErrorHandler (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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) | Delete objects from S3 after they have been retrieved. The delete is only performed if the Exchange is committed. If a rollback occurs, the object is not deleted. If this option is false, then the same objects will be retrieve over and over again on the polls. Therefore you need to use the Idempotent Consumer EIP in the route to filter out duplicates. You can filter using the AWS2S3Constants#BUCKET_NAME and AWS2S3Constants#KEY headers, or only the AWS2S3Constants#KEY header. | true | boolean |
delimiter (consumer) | The delimiter which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in. | String | |
destinationBucket (consumer) | Define the destination bucket where an object must be moved when moveAfterRead is set to true. | String | |
destinationBucketPrefix (consumer) | Define the destination bucket prefix to use when an object must be moved and moveAfterRead is set to true. | String | |
destinationBucketSuffix (consumer) | Define the destination bucket suffix to use when an object must be moved and moveAfterRead is set to true. | String | |
doneFileName (consumer) | If provided, Camel will only consume files if a done file exists. | String | |
fileName (consumer) | To get the object from the bucket with the given file name. | String | |
ignoreBody (consumer) | If it is true, the S3 Object Body will be ignored completely, if it is set to false the S3 Object will be put in the body. Setting this to true, will override any behavior defined by includeBody option. | false | boolean |
includeBody (consumer) | If it is true, the S3Object exchange will be consumed and put into the body and closed. If false the S3Object stream will be put raw into the body and the headers will be set with the S3 object metadata. This option is strongly related to autocloseBody option. In case of setting includeBody to true because the S3Object stream will be consumed then it will also be closed, while in case of includeBody false then it will be up to the caller to close the S3Object stream. However setting autocloseBody to true when includeBody is false it will schedule to close the S3Object stream automatically on exchange completion. | true | boolean |
includeFolders (consumer) | If it is true, the folders/directories will be consumed. If it is false, they will be ignored, and Exchanges will not be created for those. | true | boolean |
maxConnections (consumer) | Set the maxConnections parameter in the S3 client configuration. | 60 | int |
maxMessagesPerPoll (consumer) | Gets the maximum number of messages as a limit to poll at each polling. Gets the maximum number of messages as a limit to poll at each polling. The default value is 10. Use 0 or a negative number to set it as unlimited. | 10 | int |
moveAfterRead (consumer) | Move objects from S3 bucket to a different bucket after they have been retrieved. To accomplish the operation the destinationBucket option must be set. The copy bucket operation is only performed if the Exchange is committed. If a rollback occurs, the object is not moved. | false | boolean |
prefix (consumer) | The prefix which is used in the com.amazonaws.services.s3.model.ListObjectsRequest to only consume objects we are interested in. | 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 |
autocloseBody (consumer (advanced)) | If this option is true and includeBody is false, then the S3Object.close() method will be called on exchange completion. This option is strongly related to includeBody option. In case of setting includeBody to false and autocloseBody to false, it will be up to the caller to close the S3Object stream. Setting autocloseBody to true, will close the S3Object stream automatically. | true | 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:
| 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 | |
batchMessageNumber (producer) | The number of messages composing a batch in streaming upload mode. | 10 | int |
batchSize (producer) | The batch size (in bytes) in streaming upload mode. | 1000000 | int |
deleteAfterWrite (producer) | Delete file object after the S3 file has been uploaded. | false | boolean |
keyName (producer) | Setting the key name for an element in the bucket through endpoint parameter. | 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) | If it is true, camel will upload the file with multi part format, the part size is decided by the option of partSize. | false | boolean |
namingStrategy (producer) | The naming strategy to use in streaming upload mode. Enum values:
| progressive | AWSS3NamingStrategyEnum |
operation (producer) | The operation to do in case the user don’t want to do only an upload. Enum values:
| AWS2S3Operations | |
partSize (producer) | Setup the partSize which is used in multi part upload, the default size is 25M. | 26214400 | long |
restartingPolicy (producer) | The restarting policy to use in streaming upload mode. Enum values:
| override | AWSS3RestartingPolicyEnum |
storageClass (producer) | The storage class to set in the com.amazonaws.services.s3.model.PutObjectRequest request. | String | |
streamingUploadMode (producer) | When stream mode is true the upload to bucket will be done in streaming. | false | boolean |
streamingUploadTimeout (producer) | While streaming upload mode is true, this option set the timeout to complete upload. | long | |
awsKMSKeyId (producer (advanced)) | Define the id of KMS key to use in case KMS is enabled. | String | |
useAwsKMS (producer (advanced)) | Define if KMS must be used or not. | false | boolean |
useCustomerKey (producer (advanced)) | Define if Customer Key must be used or not. | 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 |
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 | 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. | Map | |
startScheduler (scheduler) | Whether the scheduler should be auto started. | true | boolean |
timeUnit (scheduler) | Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit |
useFixedDelay (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
accessKey (security) | Amazon AWS Access Key. | String | |
secretKey (security) | Amazon AWS Secret Key. | String |
Required S3 component options
You have to provide the amazonS3Client in the Registry or your accessKey and secretKey to access the Amazon’s S3.
5.5. Batch Consumer
This component implements the Batch Consumer.
This allows you for instance to know how many messages exists in this batch and for instance let the Aggregator aggregate this number of messages.
5.6. Usage
For example in order to read file hello.txt
from bucket helloBucket
, use the following snippet:
from("aws2-s3://helloBucket?accessKey=yourAccessKey&secretKey=yourSecretKey&prefix=hello.txt") .to("file:/var/downloaded");
5.6.1. Message headers evaluated by the S3 producer
Header | Type | Description |
---|---|---|
|
| The bucket Name which this object will be stored or which will be used for the current operation |
|
| The bucket Destination Name which will be used for the current operation |
|
| The content length of this object. |
|
| The content type of this object. |
|
| The content control of this object. |
|
| The content disposition of this object. |
|
| The content encoding of this object. |
|
| The md5 checksum of this object. |
|
| The Destination key which will be used for the current operation |
|
| The key under which this object will be stored or which will be used for the current operation |
|
| The last modified timestamp of this object. |
|
| The operation to perform. Permitted values are copyObject, deleteObject, listBuckets, deleteBucket, listObjects |
|
| The storage class of this object. |
|
|
The canned acl that will be applied to the object. see |
|
|
A well constructed Amazon S3 Access Control List object. see |
| String | Sets the server-side encryption algorithm when encrypting the object using AWS-managed keys. For example use AES256. |
|
| The version Id of the object to be stored or returned from the current operation |
|
| A map of metadata to be stored with the object in S3. More details about metadata . |
5.6.2. Message headers set by the S3 producer
Header | Type | Description |
---|---|---|
|
| The ETag value for the newly uploaded object. |
|
| The optional version ID of the newly uploaded object. |
5.6.3. Message headers set by the S3 consumer
Header | Type | Description |
---|---|---|
|
| The key under which this object is stored. |
|
| The name of the bucket in which this object is contained. |
|
| The hex encoded 128-bit MD5 digest of the associated object according to RFC 1864. This data is used as an integrity check to verify that the data received by the caller is the same data that was sent by Amazon S3. |
|
| The value of the Last-Modified header, indicating the date and time at which Amazon S3 last recorded a modification to the associated object. |
|
| The version ID of the associated Amazon S3 object if available. Version IDs are only assigned to objects when an object is uploaded to an Amazon S3 bucket that has object versioning enabled. |
|
| The Content-Type HTTP header, which indicates the type of content stored in the associated object. The value of this header is a standard MIME type. |
|
| The base64 encoded 128-bit MD5 digest of the associated object (content - not including headers) according to RFC 1864. This data is used as a message integrity check to verify that the data received by Amazon S3 is the same data that the caller sent. |
|
| The Content-Length HTTP header indicating the size of the associated object in bytes. |
|
| The optional Content-Encoding HTTP header specifying what content encodings have been applied to the object and what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type field. |
|
| The optional Content-Disposition HTTP header, which specifies presentational information such as the recommended filename for the object to be saved as. |
|
| The optional Cache-Control HTTP header which allows the user to specify caching behavior along the HTTP request/reply chain. |
| String | The server-side encryption algorithm when encrypting the object using AWS-managed keys. |
|
| A map of metadata stored with the object in S3. More details about metadata . |
5.6.4. S3 Producer operations
Camel-AWS2-S3 component provides the following operation on the producer side:
- copyObject
- deleteObject
- listBuckets
- deleteBucket
- listObjects
- getObject (this will return an S3Object instance)
- getObjectRange (this will return an S3Object instance)
- createDownloadLink
If you don’t specify an operation explicitly the producer will do: - a single file upload - a multipart upload if multiPartUpload option is enabled.
5.6.5. Advanced AmazonS3 configuration
If your Camel Application is running behind a firewall or if you need to have more control over the S3Client
instance configuration, you can create your own instance and refer to it in your Camel aws2-s3 component configuration:
from("aws2-s3://MyBucket?amazonS3Client=#client&delay=5000&maxMessagesPerPoll=5") .to("mock:result");
5.6.6. Use KMS with the S3 component
To use AWS KMS to encrypt/decrypt data by using AWS infrastructure you can use the options introduced in 2