AWS SQS Component

Table of Contents

URI Format
URI Options
Batch Consumer
Usage
Dependencies
JMS-style Selectors
See Also

Available as of Camel 2.6

The 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 are available at Amazon SQS.

URI Format

aws-sqs://queueNameOrArn[?options]

The queue 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&…​

URI Options

The AWS Simple Queue Service component has no options.

The AWS Simple Queue Service component supports 45 endpoint options which are listed below:

{% raw %}

NameGroupDefaultJava TypeDescription

queueNameOrArn

common

 

String

Required Queue name or ARN

accessKey

common

 

String

Amazon AWS Access Key

amazonSQSClient

common

 

AmazonSQS

To use the AmazonSQS as client

amazonSQSEndpoint

common

 

String

The region with which the AWS-SQS client wants to work with. Only works if Camel creates the AWS-SQS client i.e. if you explicitly set amazonSQSClient then this setting will have no effect. You would have to set it on the client you create directly

headerFilterStrategy

common

 

HeaderFilterStrategy

To use a custom HeaderFilterStrategy to map headers to/from Camel.

queueOwnerAWSAccountId

common

 

String

Specify the queue owner aws account id when you need to connect the queue with different account owner.

region

common

 

String

Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL.

secretKey

common

 

String

Amazon AWS Secret Key

attributeNames

consumer

 

String

A list of attribute names to receive when consuming. Multiple names can be separated by comma.

bridgeErrorHandler

consumer

false

boolean

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/ERROR level and ignored.

concurrentConsumers

consumer

1

int

Allows you to use multiple threads to poll the sqs queue to increase throughput

defaultVisibilityTimeout

consumer

 

Integer

The default visibility timeout (in seconds)

deleteAfterRead

consumer

true

boolean

Delete message from SQS after it has been read

deleteIfFiltered

consumer

true

boolean

Whether or not to send the DeleteMessage to the SQS queue if an exchange fails to get through a filter. If 'false' and exchange does not make it through a Camel filter upstream in the route then don’t send DeleteMessage.

extendMessageVisibility

consumer

false

boolean

If enabled then a scheduled background task will keep extending the message visibility on SQS. This is needed if it takes a long time to process the message. If set to true defaultVisibilityTimeout must be set. See details at Amazon docs.

maxMessagesPerPoll

consumer

 

int

Gets the maximum number of messages as a limit to poll at each polling. Is default unlimited but use 0 or negative number to disable it as unlimited.

messageAttributeNames

consumer

 

String

A list of message attribute names to receive when consuming. Multiple names can be separated by comma.

sendEmptyMessageWhenIdle

consumer

false

boolean

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

visibilityTimeout

consumer

 

Integer

The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request to set in the com.amazonaws.services.sqs.model.SetQueueAttributesRequest. This only make sense if its different from defaultVisibilityTimeout. It changes the queue visibility timeout attribute permanently.

waitTimeSeconds

consumer

 

Integer

Duration in seconds (0 to 20) that the ReceiveMessage action call will wait until a message is in the queue to include in the response.

exceptionHandler

consumer (advanced)

 

ExceptionHandler

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

exchangePattern

consumer (advanced)

 

ExchangePattern

Sets the exchange pattern when the consumer creates an exchange.

pollStrategy

consumer (advanced)

 

PollingConsumerPollStrategy

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.

delaySeconds

producer

 

Integer

Delay sending messages for a number of seconds.

synchronous

advanced

false

boolean

Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).

backoffErrorThreshold

scheduler

 

int

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

backoffIdleThreshold

scheduler

 

int

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

backoffMultiplier

scheduler

 

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.

delay

scheduler

500

long

Milliseconds before the next poll. You can also specify time values using units such as 60s (60 seconds) 5m30s (5 minutes and 30 seconds) and 1h (1 hour).

greedy

scheduler

false

boolean

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

initialDelay

scheduler

1000

long

Milliseconds before the first poll starts. You can also specify time values using units such as 60s (60 seconds) 5m30s (5 minutes and 30 seconds) and 1h (1 hour).

runLoggingLevel

scheduler

TRACE

LoggingLevel

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

scheduledExecutorService

scheduler

 

ScheduledExecutorService

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

scheduler

scheduler

none

ScheduledPollConsumerScheduler

To use a cron scheduler from either camel-spring or camel-quartz2 component

schedulerProperties

scheduler

 

Map

To configure additional properties when using a custom scheduler or any of the Quartz2 Spring based scheduler.

startScheduler

scheduler

true

boolean

Whether the scheduler should be auto started.

timeUnit

scheduler

MILLISECONDS

TimeUnit

Time unit for initialDelay and delay options.

useFixedDelay

scheduler

true

boolean

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

proxyHost

proxy

 

String

To define a proxy host when instantiating the SQS client

proxyPort

proxy

 

Integer

To define a proxy port when instantiating the SQS client

maximumMessageSize

queue

 

Integer

The maximumMessageSize (in bytes) an SQS message can contain for this queue.

messageRetentionPeriod

queue

 

Integer

The messageRetentionPeriod (in seconds) a message will be retained by SQS for this queue.

policy

queue

 

String

The policy for this queue

receiveMessageWaitTimeSeconds

queue

 

Integer

If you do not specify WaitTimeSeconds in the request the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how long to wait.

redrivePolicy

queue

 

String

Specify the policy that send message to DeadLetter queue. See detail at Amazon docs.

{% endraw %}

Required SQS component options

You have to provide the amazonSQSClient in the Registry or your accessKey and secretKey to access the Amazon’s SQS.

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.

Usage

Message headers set by the SQS producer

HeaderTypeDescription

CamelAwsSqsMD5OfBody

String

The MD5 checksum of the Amazon SQS message.

CamelAwsSqsMessageId

String

The Amazon SQS message ID.

CamelAwsSqsDelaySeconds

Integer

Since Camel 2.11, the delay seconds that the Amazon SQS message can be see by others.

Message headers set by the SQS consumer

HeaderTypeDescription

CamelAwsSqsMD5OfBody

String

The MD5 checksum of the Amazon SQS message.

CamelAwsSqsMessageId

String

The Amazon SQS message ID.

CamelAwsSqsReceiptHandle

String

The Amazon SQS message receipt handle.

CamelAwsSqsAttributes

Map<String, String>

The Amazon SQS message attributes.

Advanced AmazonSQS configuration

If your Camel Application is running behind a firewall or if you need to have more control over the AmazonSQS instance configuration, you can create your own instance:

AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey");

ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost("http://myProxyHost");
clientConfiguration.setProxyPort(8080);

AmazonSQS client = new AmazonSQSClient(awsCredentials, clientConfiguration);

registry.bind("client", client);

and refer to it in your Camel aws-sqs component configuration:

from("aws-sqs://MyQueue?amazonSQSClient=#client&delay=5000&maxMessagesPerPoll=5")
.to("mock:result");

Dependencies

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

pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-aws</artifactId>
    <version>${camel-version}</version>
</dependency>

where ${camel-version} must be replaced by the actual version of Camel (2.6 or higher).

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 will try 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:

from("aws-sqs://MyQueue?amazonSQSClient=#client&defaultVisibilityTimeout=5000&deleteIfFiltered=false")
.filter("${header.login} == true")
.to("mock:result");

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 5000 miliseconds, the message will become visible to other consumers.

See Also