AWS Simple Queue Service (SQS)
Since Camel 3.1
Both producer and consumer are supported
The AWS2 SQS component supports sending and receiving messages to Amazon’s SQS service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SQS. More information is available at Amazon SQS.
URI Format
aws2-sqs://queueNameOrArn[?options]
The endpoint creates the queue only when the autoCreateQueue option is true.
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS Simple Queue Service (SQS) component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The domain of Amazon SQS, to which the endpoint adds sqs and the region, as in sqs.eu-west-1.amazonaws.com, to build the queue URL when the region and queueOwnerAWSAccountId options are set. Any other value is a complete host name, for example of an SQS compatible server: the client then sends its requests to it, with the protocol of the protocol option, unless overrideEndpoint is true, and the queue URL is built with it. | amazonaws.com | String | |
Whether the endpoint creates the queue when it starts and finds no queue with this name, with the queue attributes of the options of the queue group; a name that ends with .fifo creates a FIFO queue. The consumer also creates it when a receive request finds that it does not exist, and tries again 30 seconds later if it was deleted recently. The endpoint does not look for the queue at start when queueUrl is set, or when region and queueOwnerAWSAccountId are set, so it does not create it then. | false | boolean | |
The configuration that the endpoints of this component start from. Each endpoint gets a copy of it, and the options of the endpoint replace its values. | Sqs2Configuration | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The protocol, http or https, of the URLs that the endpoint builds from the amazonAWSHost option: the queue URL when region and queueOwnerAWSAccountId are set, and the endpoint of the client when amazonAWSHost is not amazonaws.com and overrideEndpoint is false. | https | String | |
The ID of the AWS account that owns the queue, to use a queue of another account. When the region option is set too, the endpoint builds the queue URL from both without calling Amazon SQS; otherwise it looks the URL up with GetQueueUrl for this account. A queue ARN in the path sets this option. | String | ||
The AWS region of Amazon SQS, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. When the queue is given as an ARN, its region replaces the region of the component, and this option on the endpoint replaces both. Enum values:
| String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The comma separated names of the message system attributes that each receive request asks for, as Amazon SQS spells them, such as SentTimestamp, ApproximateReceiveCount, MessageGroupId or All. The consumer logs and skips an unknown name. Each received attribute is set as a header of its own name and in the CamelAwsSqsAttributes header. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
The number of threads that poll the queue at the same time, each one with its own receive requests, to increase the throughput. It applies only to the default scheduler of the consumer. | 1 | int | |
The maximum number of receive requests that the consumer runs at the same time, when maxMessagesPerPoll is above 10 and a poll is split into requests of at most 10 messages. The other requests of the poll wait for one of them to finish. A value below 1 is used as 1. | 50 | int | |
The VisibilityTimeout attribute of the queue in seconds, 0 to 43,200 (12 hours), which applies to every receive request that does not set its own, see visibilityTimeout. The endpoint sets it when it starts, on a queue it creates and on an existing queue, also for a producer. | Integer | ||
Whether the consumer deletes the message from the queue when its exchange completes successfully. A message whose exchange fails is not deleted, and Amazon SQS delivers it again when its visibility timeout runs out. When false, see deleteIfFiltered. | true | boolean | |
Whether the consumer deletes the message when its exchange completes successfully with the exchange property CamelAwsSqsDeleteFiltered set to true, for example by a Filter EIP that lets the message through. It applies only when deleteAfterRead is false, as the consumer otherwise deletes every message that completes successfully. | true | boolean | |
Whether a background task keeps the messages of a poll hidden until their exchange completes or fails, for a route that takes longer than the visibility timeout. Every half of visibilityTimeout, in whole seconds, the task calls ChangeMessageVisibilityBatch for the messages that have used 80% of their visibility timeout, and sets it to visibilityTimeout again. It requires a visibilityTimeout of at least 2 seconds; 10 seconds or more is recommended. | false | boolean | |
How long in seconds, 60 to 86,400 (24 hours), Amazon SQS reuses a data key to encrypt or decrypt messages before it calls AWS KMS again; Amazon SQS uses 300 when it is not set. The endpoint sets it as the KmsDataKeyReusePeriodSeconds attribute of the queue when it starts, also on an existing queue, and only when serverSideEncryptionEnabled is true. | Integer | ||
The ID, alias or ARN of the AWS KMS key that encrypts the messages of the queue, for example alias/aws/sqs for the AWS managed key of Amazon SQS. The endpoint sets it as the KmsMasterKeyId attribute of the queue when it starts, also on an existing queue, and only when serverSideEncryptionEnabled is true. | String | ||
The comma separated names of the message attributes that each receive request asks for; All or .* asks for all of them, and a name that ends with .* for those with that prefix. Amazon SQS returns no message attributes when this option is not set. Each received message attribute is set as a header of its own name, unless the headerFilterStrategy filters it, and in the CamelAwsSqsMessageAttributes header. | String | ||
Whether the endpoint sets the kmsMasterKeyId and kmsDataKeyReusePeriodSeconds options as attributes of the queue when it starts, on a queue it creates and on an existing queue, to encrypt the queue with AWS KMS. False does not turn off the encryption of an existing queue. | false | boolean | |
The name of a message system attribute, such as SentTimestamp, by which the consumer sorts the messages of a poll, comparing the values as text. It applies only when maxMessagesPerPoll is above 10, as the receive requests of a poll then run at the same time and return the messages in no particular order. The consumer asks for the attribute in each receive request. All and unknown names are logged and not used. | String | ||
The visibility timeout in seconds, 0 to 43,200 (12 hours), that each receive request sets on the messages it returns, so that they are hidden from other receive requests. If not set, the VisibilityTimeout attribute of the queue applies, see defaultVisibilityTimeout. It is required by extendMessageVisibility, which extends the visibility of a message by this duration. | Integer | ||
The WaitTimeSeconds of each receive request: how long in seconds, 0 to 20, the request waits for a message to arrive when the queue is empty (long polling). If not set, the ReceiveMessageWaitTimeSeconds attribute of the queue applies, which is 0 by default. | Integer | ||
The separator that splits a String body into the messages of the sendBatchMessage operation. It is a plain string, not a regular expression. | , | String | |
The delay in seconds, 0 to 900, before a sent message becomes visible to consumers. The producer sets it as the DelaySeconds of each message, and the CamelAwsSqsDelaySeconds header replaces it; it is not set for a FIFO queue, which supports only a delay of the queue. When delayQueue is true, the endpoint sets it as the DelaySeconds attribute of the queue instead. | Integer | ||
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 | |
How the producer sets the MessageDeduplicationId of a message to a FIFO queue: useExchangeId uses the ID of the exchange, followed by - and the position of the message for sendBatchMessage, and useContentBasedDeduplication sets none, so that Amazon SQS deduplicates by a hash of the body, which the queue must enable. A FIFO queue that the endpoint creates with useContentBasedDeduplication has content-based deduplication enabled. It is not used for a standard queue. Enum values:
| useExchangeId | String | |
How the producer sets the MessageGroupId of a message to a FIFO queue: useConstant puts all messages in the group CamelSingleMessageGroup, useExchangeId uses the ID of the exchange, so each message is a group of its own, and usePropertyValue uses the exchange property CamelAwsMessageGroupId. A FIFO queue requires it: without it the producer fails. It is not used for a standard queue. Enum values:
| String | ||
What the producer does when the message has more headers to send as message attributes than the 10 that Amazon SQS accepts: WARN logs a warning for each extra header and drops it, WARN_ONCE logs one warning and drops the extra headers, IGNORE drops them without a warning, and FAIL fails the exchange without sending the message. Only the headers that the headerFilterStrategy does not filter count. Enum values:
| WARN | String | |
The operation of the producer. If not set, the producer sends the body as one message. The CamelAwsSqsOperation header replaces this option. Enum values:
| Sqs2Operations | ||
Autowired To use a custom software.amazon.awssdk.services.sqs.SqsClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override, amazonAWSHost and trustAllCertificates options are not used to create a client. The endpoint does not close a client that is set or autowired. | SqsClient | ||
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 | |
Whether the delaySeconds option sets the DelaySeconds attribute of the queue when the endpoint starts, which delays every message of the queue, instead of the delay of each sent message. The CamelAwsSqsDelaySeconds header is not used then. | false | boolean | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy that the HTTP client of Amazon SQS connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon SQS connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon SQS uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The MaximumMessageSize attribute of the queue: how many bytes, 1,024 to 1,048,576 (1 MiB), a message can contain before Amazon SQS rejects it. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | Integer | ||
The MessageRetentionPeriod attribute of the queue: how long in seconds, 60 to 1,209,600 (14 days), Amazon SQS keeps a message; 345,600 (4 days) by default. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | Integer | ||
The access policy of the queue, a JSON document that the endpoint sets as the Policy attribute of the queue when it starts, on a queue it creates and on an existing queue. It is loaded from the classpath by default; use the prefix file: or http: to load it from another location. | String | ||
The URL of the queue, to use instead of the URL that the endpoint looks up or builds from the queue name, region, queueOwnerAWSAccountId and amazonAWSHost options, for example for an SQS compatible server. The endpoint then does not look for the queue or create it when it starts. | String | ||
The ReceiveMessageWaitTimeSeconds attribute of the queue: how long in seconds, 0 to 20, a receive request that does not set its own wait time waits for a message, see waitTimeSeconds. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | Integer | ||
The RedrivePolicy attribute of the queue, a JSON object with the deadLetterTargetArn of the dead-letter queue and the maxReceiveCount after which Amazon SQS moves a message to it, for example \{deadLetterTargetArn:arn:aws:sqs:us-east-1:123456789012:dlq,maxReceiveCount:5}. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | String | ||
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonSQSClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonSQSClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the HTTP client of Amazon SQS trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS Simple Queue Service (SQS) endpoint is configured using URI syntax:
aws2-sqs:queueNameOrArn
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The name of the queue, or its ARN in the form arn:aws:sqs:region:account:name, which also sets the region and queueOwnerAWSAccountId options. For a name, the endpoint looks up the URL of the queue when it starts, unless queueUrl is set, and creates the queue if autoCreateQueue is true and none exists. A queue whose name ends with .fifo is a FIFO queue. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The domain of Amazon SQS, to which the endpoint adds sqs and the region, as in sqs.eu-west-1.amazonaws.com, to build the queue URL when the region and queueOwnerAWSAccountId options are set. Any other value is a complete host name, for example of an SQS compatible server: the client then sends its requests to it, with the protocol of the protocol option, unless overrideEndpoint is true, and the queue URL is built with it. | amazonaws.com | String | |
Whether the endpoint creates the queue when it starts and finds no queue with this name, with the queue attributes of the options of the queue group; a name that ends with .fifo creates a FIFO queue. The consumer also creates it when a receive request finds that it does not exist, and tries again 30 seconds later if it was deleted recently. The endpoint does not look for the queue at start when queueUrl is set, or when region and queueOwnerAWSAccountId are set, so it does not create it then. | false | boolean | |
To use a custom HeaderFilterStrategy to choose which headers the producer sends as message attributes, and which received message attributes the consumer sets as headers. The default skips the names that start with Camel or camel, and the breadcrumbId header when sending. The producer sends a header only if its value is a non-empty String, a Number, Boolean, Date, byte[] or ByteBuffer. | HeaderFilterStrategy | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The protocol, http or https, of the URLs that the endpoint builds from the amazonAWSHost option: the queue URL when region and queueOwnerAWSAccountId are set, and the endpoint of the client when amazonAWSHost is not amazonaws.com and overrideEndpoint is false. | https | String | |
The ID of the AWS account that owns the queue, to use a queue of another account. When the region option is set too, the endpoint builds the queue URL from both without calling Amazon SQS; otherwise it looks the URL up with GetQueueUrl for this account. A queue ARN in the path sets this option. | String | ||
The AWS region of Amazon SQS, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. When the queue is given as an ARN, its region replaces the region of the component, and this option on the endpoint replaces both. Enum values:
| String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The comma separated names of the message system attributes that each receive request asks for, as Amazon SQS spells them, such as SentTimestamp, ApproximateReceiveCount, MessageGroupId or All. The consumer logs and skips an unknown name. Each received attribute is set as a header of its own name and in the CamelAwsSqsAttributes header. | String | ||
The number of threads that poll the queue at the same time, each one with its own receive requests, to increase the throughput. It applies only to the default scheduler of the consumer. | 1 | int | |
The maximum number of receive requests that the consumer runs at the same time, when maxMessagesPerPoll is above 10 and a poll is split into requests of at most 10 messages. The other requests of the poll wait for one of them to finish. A value below 1 is used as 1. | 50 | int | |
The VisibilityTimeout attribute of the queue in seconds, 0 to 43,200 (12 hours), which applies to every receive request that does not set its own, see visibilityTimeout. The endpoint sets it when it starts, on a queue it creates and on an existing queue, also for a producer. | Integer | ||
Whether the consumer deletes the message from the queue when its exchange completes successfully. A message whose exchange fails is not deleted, and Amazon SQS delivers it again when its visibility timeout runs out. When false, see deleteIfFiltered. | true | boolean | |
Whether the consumer deletes the message when its exchange completes successfully with the exchange property CamelAwsSqsDeleteFiltered set to true, for example by a Filter EIP that lets the message through. It applies only when deleteAfterRead is false, as the consumer otherwise deletes every message that completes successfully. | true | boolean | |
Whether a background task keeps the messages of a poll hidden until their exchange completes or fails, for a route that takes longer than the visibility timeout. Every half of visibilityTimeout, in whole seconds, the task calls ChangeMessageVisibilityBatch for the messages that have used 80% of their visibility timeout, and sets it to visibilityTimeout again. It requires a visibilityTimeout of at least 2 seconds; 10 seconds or more is recommended. | false | boolean | |
How long in seconds, 60 to 86,400 (24 hours), Amazon SQS reuses a data key to encrypt or decrypt messages before it calls AWS KMS again; Amazon SQS uses 300 when it is not set. The endpoint sets it as the KmsDataKeyReusePeriodSeconds attribute of the queue when it starts, also on an existing queue, and only when serverSideEncryptionEnabled is true. | Integer | ||
The ID, alias or ARN of the AWS KMS key that encrypts the messages of the queue, for example alias/aws/sqs for the AWS managed key of Amazon SQS. The endpoint sets it as the KmsMasterKeyId attribute of the queue when it starts, also on an existing queue, and only when serverSideEncryptionEnabled is true. | String | ||
The maximum number of messages to receive in each poll. A receive request returns at most 10 messages, so a value above 10 is split into several receive requests of at most 10 messages each, of which up to concurrentRequestLimit run at the same time, and 0 or a negative value receives one message per poll. The messages of a poll are routed one after the other, and the visibility timeout of each one runs from its receive: with a slow route, enable extendMessageVisibility together with visibilityTimeout, or use a visibility timeout that covers the whole poll. | 10 | int | |
The comma separated names of the message attributes that each receive request asks for; All or .* asks for all of them, and a name that ends with .* for those with that prefix. Amazon SQS returns no message attributes when this option is not set. Each received message attribute is set as a header of its own name, unless the headerFilterStrategy filters it, and in the CamelAwsSqsMessageAttributes header. | String | ||
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Whether the endpoint sets the kmsMasterKeyId and kmsDataKeyReusePeriodSeconds options as attributes of the queue when it starts, on a queue it creates and on an existing queue, to encrypt the queue with AWS KMS. False does not turn off the encryption of an existing queue. | false | boolean | |
The name of a message system attribute, such as SentTimestamp, by which the consumer sorts the messages of a poll, comparing the values as text. It applies only when maxMessagesPerPoll is above 10, as the receive requests of a poll then run at the same time and return the messages in no particular order. The consumer asks for the attribute in each receive request. All and unknown names are logged and not used. | String | ||
The visibility timeout in seconds, 0 to 43,200 (12 hours), that each receive request sets on the messages it returns, so that they are hidden from other receive requests. If not set, the VisibilityTimeout attribute of the queue applies, see defaultVisibilityTimeout. It is required by extendMessageVisibility, which extends the visibility of a message by this duration. | Integer | ||
The WaitTimeSeconds of each receive request: how long in seconds, 0 to 20, the request waits for a message to arrive when the queue is empty (long polling). If not set, the ReceiveMessageWaitTimeSeconds attribute of the queue applies, which is 0 by default. | Integer | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
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 | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
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 | ||
The separator that splits a String body into the messages of the sendBatchMessage operation. It is a plain string, not a regular expression. | , | String | |
The delay in seconds, 0 to 900, before a sent message becomes visible to consumers. The producer sets it as the DelaySeconds of each message, and the CamelAwsSqsDelaySeconds header replaces it; it is not set for a FIFO queue, which supports only a delay of the queue. When delayQueue is true, the endpoint sets it as the DelaySeconds attribute of the queue instead. | Integer | ||
How the producer sets the MessageDeduplicationId of a message to a FIFO queue: useExchangeId uses the ID of the exchange, followed by - and the position of the message for sendBatchMessage, and useContentBasedDeduplication sets none, so that Amazon SQS deduplicates by a hash of the body, which the queue must enable. A FIFO queue that the endpoint creates with useContentBasedDeduplication has content-based deduplication enabled. It is not used for a standard queue. Enum values:
| useExchangeId | String | |
How the producer sets the MessageGroupId of a message to a FIFO queue: useConstant puts all messages in the group CamelSingleMessageGroup, useExchangeId uses the ID of the exchange, so each message is a group of its own, and usePropertyValue uses the exchange property CamelAwsMessageGroupId. A FIFO queue requires it: without it the producer fails. It is not used for a standard queue. Enum values:
| String | ||
What the producer does when the message has more headers to send as message attributes than the 10 that Amazon SQS accepts: WARN logs a warning for each extra header and drops it, WARN_ONCE logs one warning and drops the extra headers, IGNORE drops them without a warning, and FAIL fails the exchange without sending the message. Only the headers that the headerFilterStrategy does not filter count. Enum values:
| WARN | String | |
The operation of the producer. If not set, the producer sends the body as one message. The CamelAwsSqsOperation header replaces this option. Enum values:
| Sqs2Operations | ||
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 | |
Autowired To use a custom software.amazon.awssdk.services.sqs.SqsClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override, amazonAWSHost and trustAllCertificates options are not used to create a client. The endpoint does not close a client that is set or autowired. | SqsClient | ||
Whether the delaySeconds option sets the DelaySeconds attribute of the queue when the endpoint starts, which delays every message of the queue, instead of the delay of each sent message. The CamelAwsSqsDelaySeconds header is not used then. | false | boolean | |
The host name of the proxy that the HTTP client of Amazon SQS connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon SQS connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon SQS uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The MaximumMessageSize attribute of the queue: how many bytes, 1,024 to 1,048,576 (1 MiB), a message can contain before Amazon SQS rejects it. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | Integer | ||
The MessageRetentionPeriod attribute of the queue: how long in seconds, 60 to 1,209,600 (14 days), Amazon SQS keeps a message; 345,600 (4 days) by default. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | Integer | ||
The access policy of the queue, a JSON document that the endpoint sets as the Policy attribute of the queue when it starts, on a queue it creates and on an existing queue. It is loaded from the classpath by default; use the prefix file: or http: to load it from another location. | String | ||
The URL of the queue, to use instead of the URL that the endpoint looks up or builds from the queue name, region, queueOwnerAWSAccountId and amazonAWSHost options, for example for an SQS compatible server. The endpoint then does not look for the queue or create it when it starts. | String | ||
The ReceiveMessageWaitTimeSeconds attribute of the queue: how long in seconds, 0 to 20, a receive request that does not set its own wait time waits for a message, see waitTimeSeconds. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | Integer | ||
The RedrivePolicy attribute of the queue, a JSON object with the deadLetterTargetArn of the dead-letter queue and the maxReceiveCount after which Amazon SQS moves a message to it, for example \{deadLetterTargetArn:arn:aws:sqs:us-east-1:123456789012:dlq,maxReceiveCount:5}. The endpoint sets it when it starts, on a queue it creates and on an existing queue. | String | ||
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
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 | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
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 | |
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 | |
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 | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonSQSClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonSQSClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the HTTP client of Amazon SQS trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS Simple Queue Service (SQS) component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsSqsAttributes (consumer) Constant: | The message system attributes of the received message that the attributeNames option asks for, as a map from the attribute name to its value. Each one is also set as a header of its own name, such as SentTimestamp. | Map | |
CamelAwsSqsMessageAttributes (consumer) Constant: | The message attributes of the received message that the messageAttributeNames option asks for, as a map from the attribute name to the MessageAttributeValue of the AWS SDK. Each one is also set as a header of its own name, unless the headerFilterStrategy filters it. | Map | |
| Constant: | The MD5 digest of the body, as a hex string: of the received message, or the one that Amazon SQS computed for the message that the producer sent. | String | |
| Constant: | The ID that Amazon SQS gave the message: the received message, or the message that the producer sent. | String | |
CamelAwsSqsReceiptHandle (common) Constant: | The receipt handle of the received message, which identifies this receive of it to delete the message or change its visibility. The deleteMessage operation of the producer deletes the message of this receipt handle. | String | |
CamelAwsSqsDelaySeconds (producer) Constant: | The delay in seconds, 0 to 900, before the sent message becomes visible to consumers. It replaces the delaySeconds option, and is not used for a FIFO queue or when delayQueue is true. | Integer | |
| Constant: | The prefix of the names of the queues that the listQueues operation returns. | String | |
| Constant: | The operation of the producer, which replaces the operation option. | String | |
CamelAwsSqsNextToken (listQueues) Constant: | The pagination token of the listQueues operation: the token of the page to return, and after the operation the token of the next page, or null if there is none. | String | |
CamelAwsSqsMaxResults (listQueues) Constant: | The maximum number of queue URLs, 1 to 1,000, that the listQueues operation returns. Amazon SQS returns a token for the next page only when it is set. | Integer | |
CamelAwsSqsIsTruncated (listQueues) Constant: | Whether the listQueues operation has more queues to return, that is whether Amazon SQS returned a token for the next page. | Boolean | |
CamelAwsSqsSequenceNumber (producer) Constant: | The sequence number that Amazon SQS gave the message that the producer sent to a FIFO queue; null for a standard queue. | String | |
CamelAwsSqsFailedMessageCount (sendBatchMessage) Constant: | The number of messages of the sendBatchMessage operation that Amazon SQS did not accept, over all its requests. | Integer | |
CamelAwsSqsSuccessfulMessageCount (sendBatchMessage) Constant: | The number of messages of the sendBatchMessage operation that Amazon SQS accepted, over all its requests. | Integer | |
CamelAwsSqsQueueName (consumer) Constant: | The name of the queue the message was received from: the last part of the path of the queueUrl option when it is set, otherwise the queue name of the endpoint. | String |
Message Body
The message body at each side of the AWS Simple Queue Service (SQS) component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The body of the SQS message. |
Producer input |
| The body of the message to send, as text: bytes, a stream or a file are read as text, and a Map or a POJO is sent as its toString(): marshal it first. sendBatchMessage takes a List of text, text that batchSeparator splits, or a SendMessageBatchRequest.
|
Producer output |
| Unchanged for a send, with the id of the message in a header; the response of the AWS SDK for the other operations.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Deterministic simulation tests
The consumer of the AWS Simple Queue Service (SQS) component is tested with deterministic simulation tests: the real consumer runs under a seeded virtual-time scheduler against a fake of the external system, which injects faults while the tests check invariants. A failing seed can be replayed. These are the fake worlds of the component:
| World | What it checks | Issues |
|---|---|---|
Fake: FakeSqs: a standard SQS queue (ReceiveMessage, DeleteMessage, ChangeMessageVisibilityBatch) bound as amazonSQSClient Tests: | Covers:
Faults:
Invariants:
|
The worlds and their tests are in the test sources of the component. How to run them, replay a seed and write a world is described in Running the tests and Writing a fake world.
Required SQS component options
You have to provide the amazonSQSClient in the Registry or your accessKey and secretKey to access the Amazon’s SQS.
Usage
Batch Consumer
This component implements the Batch Consumer.
This allows you, for instance, to know how many messages exist in this batch and for instance, let the Aggregator aggregate this number of messages.
Each poll receives up to maxMessagesPerPoll messages, 10 by default, which is the most that SQS returns to one receive request. With a higher value, each poll sends several receive requests of at most 10 messages, up to concurrentRequestLimit of them at the same time. With 0 or a negative value, each poll receives one message.
Without long polling, SQS answers a receive request from a sample of its servers, so it often returns fewer messages than asked for, or none, while more are in the queue. Set waitTimeSeconds (up to 20 seconds), or give the queue a ReceiveMessageWaitTimeSeconds attribute above 0, so that a receive request waits for messages.
The messages of a poll are routed one after the other, and the visibility timeout of each one runs from its receive. If the route is slow, the last messages of a poll can become visible again before their turn comes, and SQS then delivers them a second time. Enable extendMessageVisibility together with visibilityTimeout, which keeps every message of the poll invisible until it is processed, or use a visibility timeout that covers the processing of a whole poll.
With extendMessageVisibility, the visibility of a message is extended when 80% of its visibility timeout has passed, by a task that runs every half of the visibility timeout, in whole seconds. A visibilityTimeout below 2 seconds is rejected when the endpoint is created, as the extension would always come too late, and a value below 10 seconds is logged as a warning when the consumer starts, as it leaves only 1 to 2 seconds for the extension. Use a visibilityTimeout of 10 seconds or more.
With a FIFO queue, a poll can receive several messages of the same message group. A message that fails is not deleted, but the next messages of its group in the same poll are still routed and deleted, so the failed message is delivered again after them. Set maxMessagesPerPoll=1 if the messages of a group must keep their order when one of them fails.
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_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_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Examples
Advanced AmazonSQS configuration
If your Camel Application is running behind a firewall or if you need to have more control over the SqsClient instance configuration, you can create your own instance, and configure Camel to use your instance by the bean id.
In the example below, we use myClient as the bean id:
SqsClient creation and registry binding// create my own instance of SqsClient
SqsClient sqs = ...
// register the client into Camel registry
camelContext.getRegistry().bind("myClient", sqs);
// refer to the custom client via myClient as the bean id
from("aws2-sqs://MyQueue?amazonSQSClient=#myClient&delay=5000&maxMessagesPerPoll=5")
.to("mock:result"); DelayQueue VS Delay for Single message
When the option delayQueue is set to true, the SQS Queue will be a DelayQueue with the DelaySeconds option as delay. For more information about DelayQueue you can read the AWS SQS documentation. One important information to take into account is the following:
-
For standard queues, the per-queue delay setting is not retroactively—changing the setting doesn’t affect the delay of messages already in the queue.
-
For FIFO queues, the per-queue delay setting is retroactively—changing the setting affects the delay of messages already in the queue.
as stated in the official documentation. If you want to specify a delay on single messages, you can ignore the delayQueue option, while you can set this option to true if you need to add a fixed delay to all messages enqueued.
Server Side Encryption
There is a set of Server Side Encryption attributes for a queue. The related option are: serverSideEncryptionEnabled, kmsMasterKeyId and kmsDataKeyReusePeriodSeconds. The SSE is disabled by default. You need to explicitly set the option to true and set the related parameters as queue attributes.
JMS-style Selectors
SQS does not allow selectors, but you can effectively achieve this by using the Camel Filter EIP and setting an appropriate visibilityTimeout. When SQS dispatches a message, it will wait up to the visibility timeout before it tries to dispatch the message to a different consumer unless a DeleteMessage is received. By default, Camel will always send the DeleteMessage at the end of the route, unless the route ended in failure. To achieve appropriate filtering and not send the DeleteMessage even on successful completion of the route, use a Filter:
-
Java
-
XML
-
YAML
from("aws2-sqs://MyQueue?amazonSQSClient=#client&defaultVisibilityTimeout=5&deleteIfFiltered=true&deleteAfterRead=false")
.filter(simple("${header.login} == true"))
.setProperty("CamelAwsSqsDeleteFiltered", constant(true))
.to("mock:filter"); <route>
<from uri="aws2-sqs://MyQueue?amazonSQSClient=#client&defaultVisibilityTimeout=5&deleteIfFiltered=true&deleteAfterRead=false"/>
<filter>
<simple>${header.login} == true</simple>
<setProperty name="CamelAwsSqsDeleteFiltered">
<constant>true</constant>
</setProperty>
<to uri="mock:filter"/>
</filter>
</route> - route:
from:
uri: aws2-sqs://MyQueue
parameters:
amazonSQSClient: "#client"
defaultVisibilityTimeout: 5
deleteIfFiltered: true
deleteAfterRead: false
steps:
- filter:
simple: "${header.login} == true"
steps:
- setProperty:
name: CamelAwsSqsDeleteFiltered
constant: "true"
- to:
uri: mock:filter In Java code, you can use the constant Sqs2Constants.SQS_DELETE_FILTERED for the property name. |
In the above code, if an exchange doesn’t have an appropriate header, it will not make it through the filter AND also not be deleted from the SQS queue. After 5 seconds, the visibility timeout of the queue, the message will become visible to other consumers.
Note we must set the property CamelAwsSqsDeleteFiltered to true to instruct Camel to send the DeleteMessage, if being filtered.
Available Producer Operations
-
single message (default)
-
sendBatchMessage
-
deleteMessage
-
listQueues
-
purgeQueue
-
deleteQueue
Send Message
-
Java
-
XML
-
YAML
from("direct:start")
.setBody(constant("Camel rocks!"))
.to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=eu-west-1"); <route>
<from uri="direct:start"/>
<setBody>
<constant>Camel rocks!</constant>
</setBody>
<to uri="aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1"/>
</route> - route:
from:
uri: direct:start
steps:
- setBody:
constant: "Camel rocks!"
- to:
uri: aws2-sqs://camel-1
parameters:
accessKey: RAW(xxx)
secretKey: RAW(xxx)
region: eu-west-1 Send Batch Message
You can set a SendMessageBatchRequest or an Iterable
List body programmatically for batch messagesfrom("direct:start")
.setHeader("CamelAwsSqsOperation", constant("sendBatchMessage"))
.process(exchange -> {
List<String> c = new ArrayList<>();
c.add("team1");
c.add("team2");
c.add("team3");
c.add("team4");
exchange.getIn().setBody(c);
})
.to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=eu-west-1"); An element of the Iterable that is not a String is converted to a String.
SQS accepts at most 10 entries in a request, so a batch of more than 10 entries (from an Iterable or a String split with the batchSeparator option) is sent in requests of 10.
As result, you’ll get an exchange containing one SendMessageBatchResponse instance with the successful and the failed entries of all the requests, that you can examine to check what messages were successful and what not. The CamelAwsSqsSuccessfulMessageCount and CamelAwsSqsFailedMessageCount headers hold the number of successful and failed entries. The id set on each message of the batch will be a Random UUID.
Delete single Message
Use deleteMessage operation to delete a single message. You’ll need to set a receipt handle header for the message you want to delete.
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsSqsOperation", constant("deleteMessage"))
.setHeader("CamelAwsSqsReceiptHandle", constant("123456"))
.to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=eu-west-1"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsSqsOperation">
<constant>deleteMessage</constant>
</setHeader>
<setHeader name="CamelAwsSqsReceiptHandle">
<constant>123456</constant>
</setHeader>
<to uri="aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsSqsOperation
constant: deleteMessage
- setHeader:
name: CamelAwsSqsReceiptHandle
constant: "123456"
- to:
uri: aws2-sqs://camel-1
parameters:
accessKey: RAW(xxx)
secretKey: RAW(xxx)
region: eu-west-1 As result, you’ll get an exchange containing a DeleteMessageResponse instance, that you can use to check if the message was deleted or not.
List Queues
Use listQueues operation to list queues.
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsSqsOperation", constant("listQueues"))
.to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=eu-west-1"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsSqsOperation">
<constant>listQueues</constant>
</setHeader>
<to uri="aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsSqsOperation
constant: listQueues
- to:
uri: aws2-sqs://camel-1
parameters:
accessKey: RAW(xxx)
secretKey: RAW(xxx)
region: eu-west-1 As result, you’ll get an exchange containing a ListQueuesResponse instance, that you can examine to check the actual queues.
Purge Queue
Use purgeQueue operation to purge queue.
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelAwsSqsOperation", constant("purgeQueue"))
.to("aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=eu-west-1"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsSqsOperation">
<constant>purgeQueue</constant>
</setHeader>
<to uri="aws2-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)&region=eu-west-1"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsSqsOperation
constant: purgeQueue
- to:
uri: aws2-sqs://camel-1
parameters:
accessKey: RAW(xxx)
secretKey: RAW(xxx)
region: eu-west-1 As result you’ll get an exchange containing a PurgeQueueResponse instance.
Queue Auto-creation
With the option autoCreateQueue users are able to avoid the autocreation of an SQS Queue in case it doesn’t exist. The default for this option is false. If set to false, any operation on a non-existent queue in AWS won’t be successful and an error will be returned.
Send Batch Message and Message Deduplication Strategy
In case you’re using a SendBatchMessage Operation, you can set two different kinds of Message Deduplication Strategy: - useExchangeId - useContentBasedDeduplication
The first one will use a ExchangeIdMessageDeduplicationIdStrategy, that will use the Exchange ID as parameter The other one will use a NullMessageDeduplicationIdStrategy, that will use the body as a deduplication element.
With useExchangeId, each message of a send batch message operation gets the Exchange ID followed by - and its position in the batch, so that the messages of one batch are not duplicates of each other. With useContentBasedDeduplication, the queue must have the content based deduplication option enabled.
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-sqs</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.