camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-9609: camel-aws - SQS allow to configure attribute names easier.
Date Wed, 17 Feb 2016 09:15:09 GMT
CAMEL-9609: camel-aws - SQS allow to configure attribute names easier.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9d749129
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9d749129
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9d749129

Branch: refs/heads/master
Commit: 9d7491297aafd916c8b45424a2a6d31a49417c7a
Parents: 4e7b6e5
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Feb 17 10:13:38 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Feb 17 10:13:38 2016 +0100

----------------------------------------------------------------------
 .../component/aws/sqs/SqsConfiguration.java     | 16 +++++-----
 .../camel/component/aws/sqs/SqsConsumer.java    | 27 +++++++++++++---
 .../aws/sqs/SqsComponentConfigurationTest.java  | 33 ++++++++++----------
 3 files changed, 46 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9d749129/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
index d0b051c..22c33d5 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
@@ -55,9 +55,9 @@ public class SqsConfiguration {
     @UriParam(label = "consumer")
     private Integer visibilityTimeout;
     @UriParam(label = "consumer")
-    private Collection<String> attributeNames;
+    private String attributeNames;
     @UriParam(label = "consumer")
-    private Collection<String> messageAttributeNames;
+    private String messageAttributeNames;
     @UriParam(label = "consumer")
     private Integer waitTimeSeconds;
     @UriParam(label = "consumer")
@@ -167,25 +167,25 @@ public class SqsConfiguration {
         this.visibilityTimeout = visibilityTimeout;
     }
 
-    public Collection<String> getAttributeNames() {
+    public String getAttributeNames() {
         return attributeNames;
     }
 
     /**
-     * A list of attribute names to receive when consuming
+     * A list of attribute names to receive when consuming.  Multiple names can be separated
by comma.
      */
-    public void setAttributeNames(Collection<String> attributeNames) {
+    public void setAttributeNames(String attributeNames) {
         this.attributeNames = attributeNames;
     }
 
-    public Collection<String> getMessageAttributeNames() {
+    public String getMessageAttributeNames() {
         return messageAttributeNames;
     }
 
     /**
-     * A list of message attribute names to receive when consuming
+     * A list of message attribute names to receive when consuming. Multiple names can be
separated by comma.
      */
-    public void setMessageAttributeNames(Collection<String> messageAttributeNames)
{
+    public void setMessageAttributeNames(String messageAttributeNames) {
         this.messageAttributeNames = messageAttributeNames;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/9d749129/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
index 72f3922..0a0904e 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.aws.sqs;
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
@@ -58,11 +60,21 @@ public class SqsConsumer extends ScheduledBatchPollingConsumer {
     
     private static final Logger LOG = LoggerFactory.getLogger(SqsConsumer.class);
     private ScheduledExecutorService scheduledExecutor;
-    
     private transient String sqsConsumerToString;
+    private Collection<String> attributeNames;
+    private Collection<String> messageAttributeNames;
 
     public SqsConsumer(SqsEndpoint endpoint, Processor processor) throws NoFactoryAvailableException
{
         super(endpoint, processor);
+
+        if (getConfiguration().getAttributeNames() != null) {
+            String[] names = getConfiguration().getAttributeNames().split(",");
+            attributeNames = Arrays.asList(names);
+        }
+        if (getConfiguration().getMessageAttributeNames() != null) {
+            String[] names = getConfiguration().getMessageAttributeNames().split(",");
+            messageAttributeNames = Arrays.asList(names);
+        }
     }
 
     @Override
@@ -74,10 +86,15 @@ public class SqsConsumer extends ScheduledBatchPollingConsumer {
         ReceiveMessageRequest request = new ReceiveMessageRequest(getQueueUrl());
         request.setMaxNumberOfMessages(getMaxMessagesPerPoll() > 0 ? getMaxMessagesPerPoll()
: null);
         request.setVisibilityTimeout(getConfiguration().getVisibilityTimeout() != null ?
getConfiguration().getVisibilityTimeout() : null);
-        request.setAttributeNames(getConfiguration().getAttributeNames() != null ? getConfiguration().getAttributeNames()
: null);
-        request.setMessageAttributeNames(getConfiguration().getMessageAttributeNames() !=
null ? getConfiguration().getMessageAttributeNames() : null);
         request.setWaitTimeSeconds(getConfiguration().getWaitTimeSeconds() != null ? getConfiguration().getWaitTimeSeconds()
: null);
 
+        if (attributeNames != null) {
+            request.setAttributeNames(attributeNames);
+        }
+        if (messageAttributeNames != null) {
+            request.setMessageAttributeNames(messageAttributeNames);
+        }
+
         LOG.trace("Receiving messages with request [{}]...", request);
         
         ReceiveMessageResult messageResult = null;
@@ -106,10 +123,10 @@ public class SqsConsumer extends ScheduledBatchPollingConsumer {
                 Thread.sleep(30000);
                 getEndpoint().createQueue(getClient());
             } catch (Exception e) {
-                LOG.error("failed to retry queue connection.", e);
+                LOG.warn("failed to retry queue connection.", e);
             }
         } catch (Exception e) {
-            LOG.error("Could not connect to queue in amazon.", e);
+            LOG.warn("Could not connect to queue in amazon.", e);
         }
     }
     

http://git-wip-us.apache.org/repos/asf/camel/blob/9d749129/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
index e7eac1f..7da07bb 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.component.aws.sqs;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.impl.PropertyPlaceholderDelegateRegistry;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -48,6 +45,18 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
     }
     
     @Test
+    public void createEndpointAttributeNames() throws Exception {
+        SqsComponent component = new SqsComponent(context);
+        SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&attributeNames=foo,bar");
+
+        assertEquals("MyQueue", endpoint.getConfiguration().getQueueName());
+        assertEquals("xxx", endpoint.getConfiguration().getAccessKey());
+        assertEquals("yyy", endpoint.getConfiguration().getSecretKey());
+        assertNull(endpoint.getConfiguration().getAmazonSQSClient());
+        assertEquals("foo,bar", endpoint.getConfiguration().getAttributeNames());
+    }
+
+    @Test
     public void createEndpointWithMinimalConfigurationAndProvidedClient() throws Exception
{
         AmazonSQSClientMock mock = new AmazonSQSClientMock();
         
@@ -74,19 +83,9 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithMaximalConfiguration() throws Exception {
-        List<String> attributeNames = new ArrayList<String>();
-        attributeNames.add("color");
-        attributeNames.add("size");
-        List<String> messageAttributeNames = new ArrayList<String>();
-        messageAttributeNames.add("msgColor");
-        messageAttributeNames.add("msgSize");
-        
-        ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("attributeNames",
attributeNames);
-        ((JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry()).bind("messageAttributeNames",
messageAttributeNames);
-
         SqsComponent component = new SqsComponent(context);
-        SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSEndpoint=sns.eu-west-1.amazonaws.com&accessKey=xxx&secretKey=yyy&attributeNames=#attributeNames"
-                + "&messageAttributeNames=#messageAttributeNames&DefaultVisibilityTimeout=1000&visibilityTimeout=2000&maximumMessageSize=65536&messageRetentionPeriod=1209600&policy="
+        SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSEndpoint=sns.eu-west-1.amazonaws.com&accessKey=xxx&secretKey=yyy&attributeNames=color,size"
+                + "&messageAttributeNames=msgColor,msgSize&DefaultVisibilityTimeout=1000&visibilityTimeout=2000&maximumMessageSize=65536&messageRetentionPeriod=1209600&policy="
                 + "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyQueue%2FSQSDefaultPolicy%22%2C%22Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22"
                 + "Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyQueue%22%7D%5D%7D"
                 + "&delaySeconds=123&receiveMessageWaitTimeSeconds=10&waitTimeSeconds=20"
@@ -97,8 +96,8 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
         assertEquals("xxx", endpoint.getConfiguration().getAccessKey());
         assertEquals("yyy", endpoint.getConfiguration().getSecretKey());
         assertNull(endpoint.getConfiguration().getAmazonSQSClient());
-        assertSame(attributeNames, endpoint.getConfiguration().getAttributeNames());
-        assertSame(messageAttributeNames, endpoint.getConfiguration().getMessageAttributeNames());
+        assertEquals("color,size", endpoint.getConfiguration().getAttributeNames());
+        assertEquals("msgColor,msgSize", endpoint.getConfiguration().getMessageAttributeNames());
         assertEquals(new Integer(1000), endpoint.getConfiguration().getDefaultVisibilityTimeout());
         assertEquals(new Integer(2000), endpoint.getConfiguration().getVisibilityTimeout());
         assertEquals("sns.eu-west-1.amazonaws.com", endpoint.getConfiguration().getAmazonSQSEndpoint());


Mime
View raw message