camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Posta (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > AWS-SQS
Date Fri, 11 Oct 2013 13:19:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/AWS-SQS">AWS-SQS</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~ceposta">Christian
Posta</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >|defaultVisibilityTimeout | {{null}}
| Shared | The visibility timeout (in seconds) to set in the {{com.amazonaws.services.sqs.model.CreateQueueRequest}}.
| <br>|deleteAfterRead | {{true}} | Consumer | Delete message from SQS after it has
been read | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|deleteIfFiltered
| {{true}} | Consumer | Whether or not to send the DeleteMessage to the SQS queue if an exchange
fails to get through a filter. If &#39;false&#39; and exchange does not make it through
a Camel filter upstream in the route, then don&#39;t send DeleteMessage. |  <br></td></tr>
            <tr><td class="diff-unchanged" >|maxMessagesPerPoll| {{null}} | Consumer
| The maximum number of messages which can be received in one poll to set in the {{com.amazonaws.services.sqs.model.ReceiveMessageRequest}}.
| <br>|visibilityTimeout | {{null}} | Shared | 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. | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >where {{$\{camel-version\}}} must
be replaced by the actual version of Camel (2.6 or higher). <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
JMS-style Selectors  <br>SQS does not allow selectors, but you can effectively achieve
this by using the [Camel Filter EIP|Message Filter] 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: <br> <br>{code} <br>from(&quot;aws-sqs://MyQueue?amazonSQSClient=#client&amp;defaultVisibilityTimeout=5000&amp;deleteIfFiltered=false&quot;)
<br>.filter(&quot;${header.login} == true&quot;) <br>.to(&quot;mock:result&quot;);
<br>{code} <br> <br>In the above code, if an exchange doesn&#39;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.
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >{include:Endpoint See Also} <br>-
[AWS Component|AWS] <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="AWS-SQS-SQSComponent"></a>SQS Component</h2>
<p><b>Available as of Camel 2.6</b></p>

<p>The sqs component supports sending and receiving messages to <a href="http://aws.amazon.com/sqs"
class="external-link" rel="nofollow">Amazon's SQS</a> service.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Prerequisites</b><br
/>You must have a valid Amazon Web Services developer account, and be signed up to use
Amazon SQS. More information are available at <a href="http://aws.amazon.com/sqs" class="external-link"
rel="nofollow">Amazon SQS</a>.</td></tr></table></div>

<h3><a name="AWS-SQS-URIFormat"></a>URI Format</h3>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
aws-sqs://queue-name[?options]
</pre>
</div></div>
<p>The queue will be created if they don't already exists.<br/>
You can append query options to the URI in the following format, ?options=value&amp;option2=value&amp;...</p>

<h3><a name="AWS-SQS-URIOptions"></a>URI Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Context </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'>amazonSQSClient </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> Reference to a <tt>com.amazonaws.services.sqs.AmazonSQS</tt>
in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.
</td>
</tr>
<tr>
<td class='confluenceTd'>accessKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> Amazon AWS Access Key </td>
</tr>
<tr>
<td class='confluenceTd'>secretKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> Amazon AWS Secret Key </td>
</tr>
<tr>
<td class='confluenceTd'>amazonSQSEndpoint </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> 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
</td>
</tr>
<tr>
<td class='confluenceTd'>attributeNames </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> A list of attributes to set in the <tt>com.amazonaws.services.sqs.model.ReceiveMessageRequest</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'>defaultVisibilityTimeout </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> The visibility timeout (in seconds) to set in the <tt>com.amazonaws.services.sqs.model.CreateQueueRequest</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'>deleteAfterRead </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> Delete message from SQS after it has been read </td>
</tr>
<tr>
<td class='confluenceTd'>deleteIfFiltered </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> 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. </td>
</tr>
<tr>
<td class='confluenceTd'>maxMessagesPerPoll</td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> The maximum number of messages which can be received in one
poll to set in the <tt>com.amazonaws.services.sqs.model.ReceiveMessageRequest</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'>visibilityTimeout </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> 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 <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>. This
only make sense if its different from <tt>defaultVisibilityTimeout</tt>. It changes
the queue visibility timeout attribute permanently. </td>
</tr>
<tr>
<td class='confluenceTd'>messageVisibilityTimeout </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> 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 <tt>com.amazonaws.services.sqs.model.ReceiveMessageRequest</tt>.
It does <b>NOT</b> change the queue visibility timeout attribute permanently.
</td>
</tr>
<tr>
<td class='confluenceTd'> extendMessageVisibility </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> If enabled then a scheduled
background task will keep extending the message visibility on SQS. This is needed if it taks
a long time to process the message. If set to true <tt>defaultVisibilityTimeout</tt>
must be set.  See details at <a href="http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryChangeMessageVisibility.html"
class="external-link" rel="nofollow">Amazon docs</a>. </td>
</tr>
<tr>
<td class='confluenceTd'>maximumMessageSize </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The maximumMessageSize (in bytes)
an SQS message can contain for this queue, to set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'>messageRetentionPeriod </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The messageRetentionPeriod (in
seconds) a message will be retained by SQS for this queue, to set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'>policy </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> The policy for this queue to
set in the <tt>com.amazonaws.services.sqs.model.SetQueueAttributesRequest</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'>delaySeconds </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'> <b>Camel 2.9.3:</b> Delay sending messages for
a number of seconds. </td>
</tr>
<tr>
<td class='confluenceTd'>waitTimeSeconds </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> 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. </td>
</tr>
<tr>
<td class='confluenceTd'>receiveMessageWaitTimeSeconds </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Shared </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> If you do not specify WaitTimeSeconds
in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine how
long to wait. </td>
</tr>
<tr>
<td class='confluenceTd'>queueOwnerAWSAccountId </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.12:</b> Specify the queue owner aws
account id when you need to connect the queue with different account owner. </td>
</tr>
</tbody></table>
</div>
</div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Required
SQS component options</b><br />You have to provide the amazonSQSClient in the
<a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> or
your accessKey and secretKey to access the <a href="http://aws.amazon.com/sqs" class="external-link"
rel="nofollow">Amazon's SQS</a>.</td></tr></table></div>

<h3><a name="AWS-SQS-BatchConsumer"></a>Batch Consumer</h3>
<p>This component implements the <a href="/confluence/display/CAMEL/Batch+Consumer"
title="Batch Consumer">Batch Consumer</a>. </p>

<p>This allows you for instance to know how many messages exists in this batch and for
instance let the <a href="/confluence/display/CAMEL/Aggregator" title="Aggregator">Aggregator</a>
aggregate this number of messages.</p>

<h3><a name="AWS-SQS-Usage"></a>Usage</h3>
<h4><a name="AWS-SQS-MessageheaderssetbytheSQSproducer"></a>Message headers
set by the SQS producer</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsMD5OfBody</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The MD5 checksum of the Amazon SQS message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsMessageId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The Amazon SQS message ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsDelaySeconds</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> Since <b>Camel 2.11</b>, the delay seconds that
the Amazon SQS message can be see by others. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="AWS-SQS-MessageheaderssetbytheSQSconsumer"></a>Message headers
set by the SQS consumer</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsMD5OfBody</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The MD5 checksum of the Amazon SQS message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsMessageId</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> The Amazon SQS message ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsReceiptHandle</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'>  The Amazon SQS message receipt handle. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelAwsSqsAttributes</tt> </td>
<td class='confluenceTd'> <tt>Map&lt;String, String&gt;</tt> </td>
<td class='confluenceTd'> The Amazon SQS message attributes. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="AWS-SQS-AdvancedAmazonSQSconfiguration"></a>Advanced AmazonSQS
configuration</h4>
<p>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:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
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);
</pre>
</div></div>

<p>and refer to it in your Camel aws-sqs component configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("aws-sqs://MyQueue?amazonSQSClient=#client&amp;delay=5000&amp;maxMessagesPerPoll=5")
.to("mock:result");
</pre>
</div></div>

<h3><a name="AWS-SQS-Dependencies"></a>Dependencies</h3>
<p>Maven users will need to add the following dependency to their pom.xml.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>pom.xml</b></div><div class="codeContent
panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-aws&lt;/artifactId&gt;
    &lt;version&gt;${camel-version}&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

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

<h3><a name="AWS-SQS-JMSstyleSelectors"></a>JMS-style Selectors </h3>
<p>SQS does not allow selectors, but you can effectively achieve this by using the <a
href="/confluence/display/CAMEL/Message+Filter" title="Message Filter">Camel Filter EIP</a>
and setting an appropriate <tt>visibilityTimeout</tt>. 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:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("aws-sqs://MyQueue?amazonSQSClient=#client&amp;defaultVisibilityTimeout=5000&amp;deleteIfFiltered=false")
.filter("${header.login} == true")
.to("mock:result");
</pre>
</div></div>

<p>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.</p>

<h3><a name="AWS-SQS-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/AWS" title="AWS">AWS Component</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/AWS-SQS">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24838327&revisedVersion=27&originalVersion=26">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message