You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/05/24 12:52:40 UTC
[camel] 01/06: CAMEL-13570 - Camel AWS-SQS: Make the autocreation
of the queue configurable
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4fd8060a3cd1b46bd2c89640fb1fc56b485d8ab2
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri May 24 13:22:30 2019 +0200
CAMEL-13570 - Camel AWS-SQS: Make the autocreation of the queue configurable
---
.../src/main/docs/aws-sqs-component.adoc | 5 ++---
.../camel/component/aws/sqs/SqsConfiguration.java | 15 ++++++++++++-
.../camel/component/aws/sqs/SqsConsumer.java | 4 +++-
.../camel/component/aws/sqs/SqsEndpoint.java | 2 +-
.../aws/sqs/SqsComponentConfigurationTest.java | 15 +++++++++++++
.../sqs/springboot/SqsComponentConfiguration.java | 25 +++++++++++-----------
6 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/components/camel-aws-sqs/src/main/docs/aws-sqs-component.adoc b/components/camel-aws-sqs/src/main/docs/aws-sqs-component.adoc
index 4784854..a4ff572 100644
--- a/components/camel-aws-sqs/src/main/docs/aws-sqs-component.adoc
+++ b/components/camel-aws-sqs/src/main/docs/aws-sqs-component.adoc
@@ -27,7 +27,7 @@ The queue will be created if they don't already exists. +
// component options: START
-The AWS Simple Queue Service component supports 6 options, which are listed below.
+The AWS Simple Queue Service component supports 5 options, which are listed below.
@@ -39,7 +39,6 @@ The AWS Simple Queue Service component supports 6 options, which are listed belo
| *secretKey* (common) | Amazon AWS Secret Key | | String
| *region* (common) | Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. | | String
| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
-| *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
|===
// component options: END
@@ -77,6 +76,7 @@ with the following path and query parameters:
| Name | Description | Default | Type
| *amazonAWSHost* (common) | The hostname of the Amazon AWS cloud. | amazonaws.com | String
| *amazonSQSClient* (common) | To use the AmazonSQS as client | | AmazonSQS
+| *autoCreateQueue* (common) | Setting the autocreation of the queue | false | boolean
| *headerFilterStrategy* (common) | To use a custom HeaderFilterStrategy to map headers to/from Camel. | | HeaderFilterStrategy
| *queueOwnerAWSAccountId* (common) | Specify the queue owner aws account id when you need to connect the queue with different account owner. | | String
| *region* (common) | Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. | | String
@@ -102,7 +102,6 @@ with the following path and query parameters:
| *messageDeduplicationId Strategy* (producer) | Only for FIFO queues. Strategy for setting the messageDeduplicationId on the message. Can be one of the following options: useExchangeId, useContentBasedDeduplication. For the useContentBasedDeduplication option, no messageDeduplicationId will be set on the message. | useExchangeId | MessageDeduplicationId Strategy
| *messageGroupIdStrategy* (producer) | Only for FIFO queues. Strategy for setting the messageGroupId on the message. Can be one of the following options: useConstant, useExchangeId, usePropertyValue. For the usePropertyValue option, the value of property CamelAwsMessageGroupId will be used. | | MessageGroupIdStrategy
| *operation* (producer) | The operation to do in case the user don't want to send only a message | | SqsOperations
-| *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *delayQueue* (advanced) | Define if you want to apply delaySeconds option to the queue or on single messages | false | boolean
| *queueUrl* (advanced) | To define the queueUrl explicitly. All other parameters, which would influence the queueUrl, are ignored. This parameter is intended to be used, to connect to a mock implementation of SQS, for testing purposes. | | String
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
index 9e01171..3a17d7a 100644
--- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
+++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java
@@ -43,6 +43,8 @@ public class SqsConfiguration implements Cloneable {
private String proxyHost;
@UriParam(label = "proxy")
private Integer proxyPort;
+ @UriParam
+ private boolean autoCreateQueue = true;
// consumer properties
@UriParam(label = "consumer", defaultValue = "true")
@@ -490,11 +492,22 @@ public class SqsConfiguration implements Cloneable {
this.operation = operation;
}
+ public boolean isAutoCreateQueue() {
+ return autoCreateQueue;
+ }
+
+ /**
+ * Setting the autocreation of the queue
+ */
+ public void setAutoCreateQueue(boolean autoCreateQueue) {
+ this.autoCreateQueue = autoCreateQueue;
+ }
+
// *************************************************
//
// *************************************************
- public SqsConfiguration copy() {
+ public SqsConfiguration copy() {
try {
return (SqsConfiguration)super.clone();
} catch (CloneNotSupportedException e) {
diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
index 8d3694d..b6892be 100644
--- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
+++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java
@@ -110,7 +110,9 @@ public class SqsConsumer extends ScheduledBatchPollingConsumer {
public void reConnectToQueue() {
try {
- getEndpoint().createQueue(getClient());
+ if (getEndpoint().getConfiguration().isAutoCreateQueue()) {
+ getEndpoint().createQueue(getClient());
+ }
} catch (QueueDeletedRecentlyException qdr) {
log.debug("Queue recently deleted, will retry in 30 seconds.");
try {
diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
index d7e8579..18fd053 100644
--- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
+++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
@@ -142,7 +142,7 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt
}
}
- if (queueUrl == null) {
+ if (queueUrl == null && configuration.isAutoCreateQueue()) {
createQueue(client);
} else {
log.debug("Using Amazon SQS queue url: {}", queueUrl);
diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
index 201539d..b80ff53 100644
--- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
+++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
@@ -264,4 +264,19 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
}
+
+ @Test
+ public void createEndpointWithoutAutoCreation() throws Exception {
+ SqsComponent component = new SqsComponent(context);
+ component.setAccessKey("XXX");
+ component.setSecretKey("YYY");
+ component.setRegion(Regions.US_WEST_1.toString());
+ SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1&autoCreateQueue=false");
+
+ assertEquals("MyQueue", endpoint.getConfiguration().getQueueName());
+ assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
+ assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
+ assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
+ assertEquals(false, endpoint.getConfiguration().isAutoCreateQueue());
+ }
}
diff --git a/platforms/spring-boot/components-starter/camel-aws-sqs-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-sqs-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java
index b3f0896..3082327 100644
--- a/platforms/spring-boot/components-starter/camel-aws-sqs-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-aws-sqs-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java
@@ -62,11 +62,6 @@ public class SqsComponentConfiguration
* placeholders.
*/
private Boolean resolvePropertyPlaceholders = true;
- /**
- * Whether the component should use basic property binding (Camel 2.x) or
- * the newer property binding with additional capabilities
- */
- private Boolean basicPropertyBinding = false;
public SqsConfigurationNestedConfiguration getConfiguration() {
return configuration;
@@ -110,14 +105,6 @@ public class SqsComponentConfiguration
this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
}
- public Boolean getBasicPropertyBinding() {
- return basicPropertyBinding;
- }
-
- public void setBasicPropertyBinding(Boolean basicPropertyBinding) {
- this.basicPropertyBinding = basicPropertyBinding;
- }
-
public static class SqsConfigurationNestedConfiguration {
public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.sqs.SqsConfiguration.class;
/**
@@ -287,6 +274,10 @@ public class SqsComponentConfiguration
* message
*/
private SqsOperations operation;
+ /**
+ * Setting the autocreation of the queue
+ */
+ private Boolean autoCreateQueue = false;
public String getAmazonAWSHost() {
return amazonAWSHost;
@@ -547,5 +538,13 @@ public class SqsComponentConfiguration
public void setOperation(SqsOperations operation) {
this.operation = operation;
}
+
+ public Boolean getAutoCreateQueue() {
+ return autoCreateQueue;
+ }
+
+ public void setAutoCreateQueue(Boolean autoCreateQueue) {
+ this.autoCreateQueue = autoCreateQueue;
+ }
}
}
\ No newline at end of file