camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1375718 - in /camel/trunk/components/camel-aws/src: main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java
Date Tue, 21 Aug 2012 19:05:45 GMT
Author: cmueller
Date: Tue Aug 21 19:05:44 2012
New Revision: 1375718

URL: http://svn.apache.org/viewvc?rev=1375718&view=rev
Log:
CAMEL-5528: Improve how the AWS-SQS component create a new queue with additional attributes

Modified:
    camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
    camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java

Modified: camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java?rev=1375718&r1=1375717&r2=1375718&view=diff
==============================================================================
--- camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
(original)
+++ camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
Tue Aug 21 19:05:44 2012
@@ -23,7 +23,7 @@ import com.amazonaws.auth.BasicAWSCreden
 import com.amazonaws.services.sqs.AmazonSQSClient;
 import com.amazonaws.services.sqs.model.CreateQueueRequest;
 import com.amazonaws.services.sqs.model.CreateQueueResult;
-import com.amazonaws.services.sqs.model.SetQueueAttributesRequest;
+import com.amazonaws.services.sqs.model.QueueAttributeName;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
@@ -37,7 +37,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-
 /**
  * Defines the <a href="http://camel.apache.org/aws.html">AWS SQS Endpoint</a>.
 
  *
@@ -78,39 +77,24 @@ public class SqsEndpoint extends Schedul
         
         // creates a new queue, or returns the URL of an existing one
         CreateQueueRequest request = new CreateQueueRequest(configuration.getQueueName());
-        
-        LOG.trace("Creating queue [{}] with request [{}]...", configuration.getQueueName(),
request);
-        
-        CreateQueueResult queueResult = client.createQueue(request);
-        queueUrl = queueResult.getQueueUrl();
-        
-        LOG.trace("Queue created and available at: {}", queueUrl);
-
-        // According to the documentation, only one setting can be made at a time, even though
they go into a Map.
         if (getConfiguration().getDefaultVisibilityTimeout() != null) {
-            updateAttribute("VisibilityTimeout", getConfiguration().getDefaultVisibilityTimeout());
+            request.getAttributes().put(QueueAttributeName.VisibilityTimeout.name(), String.valueOf(getConfiguration().getDefaultVisibilityTimeout()));
         }
         if (getConfiguration().getMaximumMessageSize() != null) {
-            updateAttribute("MaximumMessageSize", getConfiguration().getMaximumMessageSize());
+            request.getAttributes().put(QueueAttributeName.MaximumMessageSize.name(), String.valueOf(getConfiguration().getMaximumMessageSize()));
         }
         if (getConfiguration().getMessageRetentionPeriod() != null) {
-            updateAttribute("MessageRetentionPeriod", getConfiguration().getMessageRetentionPeriod());
+            request.getAttributes().put(QueueAttributeName.MessageRetentionPeriod.name(),
String.valueOf(getConfiguration().getMessageRetentionPeriod()));
         }
         if (getConfiguration().getPolicy() != null) {
-            updateAttribute("Policy", getConfiguration().getPolicy());
-        }
-    }
-
-    protected void updateAttribute(String attribute, Object value) {
-        SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest();
-        setQueueAttributesRequest.setQueueUrl(queueUrl);
-        setQueueAttributesRequest.getAttributes().put(attribute, String.valueOf(value));
-        
-        LOG.trace("Updating queue [{}] with request: {}", configuration.getQueueName(), setQueueAttributesRequest);
+            request.getAttributes().put(QueueAttributeName.Policy.name(), String.valueOf(getConfiguration().getPolicy()));
+        }        
+        LOG.trace("Creating queue [{}] with request [{}]...", configuration.getQueueName(),
request);
         
-        client.setQueueAttributes(setQueueAttributesRequest);
+        CreateQueueResult queueResult = client.createQueue(request);
+        queueUrl = queueResult.getQueueUrl();
         
-        LOG.trace("Queue updated");
+        LOG.trace("Queue created and available at: {}", queueUrl);
     }
 
     @Override

Modified: camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java?rev=1375718&r1=1375717&r2=1375718&view=diff
==============================================================================
--- camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java
(original)
+++ camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java
Tue Aug 21 19:05:44 2012
@@ -87,8 +87,8 @@ public class SqsComponentIntegrationTest
     }
     
     protected RouteBuilder createRouteBuilder() throws Exception {
-        final String sqsEndpointUri = String.format("aws-sqs://MyNewCamelQueue?accessKey=%s&secretKey=%s&messageRetentionPeriod=%s&maximumMessageSize=%s&policy=%s",
-                accessKey, secretKey, "1209600", "65536", "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyNewCamelQueue%2FSQSDefaultPolicy%22%2C%22"
+        final String sqsEndpointUri = String.format("aws-sqs://MyNewCamelQueue?accessKey=%s&secretKey=%s&messageRetentionPeriod=%s&maximumMessageSize=%s&visibilityTimeout=%s&policy=%s",
+                accessKey, secretKey, "1209600", "65536", "60", "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyNewCamelQueue%2FSQSDefaultPolicy%22%2C%22"
                         + "Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22"
                         + "Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyNewCamelQueue%22%7D%5D%7D");
         



Mime
View raw message