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 8bb180a1c179beca139ed77e1647415addef6d2d Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Fri Jul 24 08:54:43 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-MQ --- .../component/aws/mq/MQComponentConfigurer.java | 5 ++++ .../component/aws/mq/MQEndpointConfigurer.java | 5 ++++ .../org/apache/camel/component/aws/mq/aws-mq.json | 2 ++ .../src/main/docs/aws-mq-component.adoc | 6 +++-- .../apache/camel/component/aws/mq/MQComponent.java | 4 +++- .../camel/component/aws/mq/MQConfiguration.java | 15 ++++++++++++ .../aws/mq/MQComponentClientRegistryTest.java | 24 +++++++++++++++++++ .../dsl/AwsMqComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/MQEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 106 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQComponentConfigurer.java b/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQComponentConfigurer.java index 26d5045..c3dc80a 100644 --- a/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQComponentConfigurer.java +++ b/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQComponentConfigurer.java @@ -30,6 +30,8 @@ public class MQComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonmqclient": case "amazonMqClient": getOrCreateConfiguration(target).setAmazonMqClient(property(camelContext, com.amazonaws.services.mq.AmazonMQ.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": getOrCreateConfiguration(target).setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws.mq.MQConfiguration.class, value)); return true; @@ -54,6 +56,7 @@ public class MQComponentConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonMqClient", com.amazonaws.services.mq.AmazonMQ.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.mq.MQConfiguration.class); answer.put("lazyStartProducer", boolean.class); @@ -74,6 +77,8 @@ public class MQComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); case "amazonmqclient": case "amazonMqClient": return getOrCreateConfiguration(target).getAmazonMqClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return getOrCreateConfiguration(target).isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "configuration": return target.getConfiguration(); diff --git a/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQEndpointConfigurer.java b/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQEndpointConfigurer.java index 525b2e7..2872cdc 100644 --- a/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQEndpointConfigurer.java +++ b/components/camel-aws-mq/src/generated/java/org/apache/camel/component/aws/mq/MQEndpointConfigurer.java @@ -23,6 +23,8 @@ public class MQEndpointConfigurer extends PropertyConfigurerSupport implements G case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonmqclient": case "amazonMqClient": target.getConfiguration().setAmazonMqClient(property(camelContext, com.amazonaws.services.mq.AmazonMQ.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": target.getConfiguration().setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "lazystartproducer": @@ -47,6 +49,7 @@ public class MQEndpointConfigurer extends PropertyConfigurerSupport implements G Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonMqClient", com.amazonaws.services.mq.AmazonMQ.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("lazyStartProducer", boolean.class); answer.put("operation", org.apache.camel.component.aws.mq.MQOperations.class); @@ -67,6 +70,8 @@ public class MQEndpointConfigurer extends PropertyConfigurerSupport implements G case "accessKey": return target.getConfiguration().getAccessKey(); case "amazonmqclient": case "amazonMqClient": return target.getConfiguration().getAmazonMqClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "lazystartproducer": diff --git a/components/camel-aws-mq/src/generated/resources/org/apache/camel/component/aws/mq/aws-mq.json b/components/camel-aws-mq/src/generated/resources/org/apache/camel/component/aws/mq/aws-mq.json index afdf320..b2e8d16 100644 --- a/components/camel-aws-mq/src/generated/resources/org/apache/camel/component/aws/mq/aws-mq.json +++ b/components/camel-aws-mq/src/generated/resources/org/apache/camel/component/aws/mq/aws-mq.json @@ -21,6 +21,7 @@ "lenientProperties": false }, "componentProperties": { + "autoDiscoverClient": { "kind": "property", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry a [...] "accessKey": { "kind": "property", "displayName": "Access Key", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "amazonMqClient": { "kind": "property", "displayName": "Amazon Mq Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.mq.AmazonMQ", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "To use a existing configured AmazonMQClient as client" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.mq.MQConfiguration", "deprecated": false, "secret": false, "description": "The Component configuration" }, @@ -35,6 +36,7 @@ }, "properties": { "label": { "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "Logical name" }, + "autoDiscoverClient": { "kind": "parameter", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry [...] "accessKey": { "kind": "parameter", "displayName": "Access Key", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "amazonMqClient": { "kind": "parameter", "displayName": "Amazon Mq Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.mq.AmazonMQ", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.mq.MQConfiguration", "configurationField": "configuration", "description": "To use a existing configured AmazonMQClient as client" }, "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the [...] diff --git a/components/camel-aws-mq/src/main/docs/aws-mq-component.adoc b/components/camel-aws-mq/src/main/docs/aws-mq-component.adoc index 842be3b..7a8cd82 100644 --- a/components/camel-aws-mq/src/main/docs/aws-mq-component.adoc +++ b/components/camel-aws-mq/src/main/docs/aws-mq-component.adoc @@ -36,13 +36,14 @@ You can append query options to the URI in the following format, // component options: START -The AWS MQ component supports 11 options, which are listed below. +The AWS MQ component supports 12 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *accessKey* (producer) | Amazon AWS Access Key | | String | *amazonMqClient* (producer) | To use a existing configured AmazonMQClient as client | | AmazonMQ | *configuration* (producer) | The Component configuration | | MQConfiguration @@ -79,12 +80,13 @@ with the following path and query parameters: |=== -=== Query Parameters (11 parameters): +=== Query Parameters (12 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *accessKey* (producer) | Amazon AWS Access Key | | String | *amazonMqClient* (producer) | To use a existing configured AmazonMQClient as client | | AmazonMQ | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] diff --git a/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java b/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java index e538445..28a6624 100644 --- a/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java +++ b/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQComponent.java @@ -50,7 +50,9 @@ public class MQComponent extends DefaultComponent { MQConfiguration configuration = this.configuration != null ? this.configuration.copy() : new MQConfiguration(); MQEndpoint endpoint = new MQEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getAmazonMqClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("amazonMQClient or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java b/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java index 817589a..56b561a 100644 --- a/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java +++ b/components/camel-aws-mq/src/main/java/org/apache/camel/component/aws/mq/MQConfiguration.java @@ -47,6 +47,8 @@ public class MQConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public AmazonMQ getAmazonMqClient() { return amazonMqClient; @@ -137,6 +139,19 @@ public class MQConfiguration implements Cloneable { this.region = region; } + public boolean isAutoDiscoverClient() { + return autoDiscoverClient; + } + + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + */ + public void setAutoDiscoverClient(boolean autoDiscoverClient) { + this.autoDiscoverClient = autoDiscoverClient; + } + // ************************************************* // // ************************************************* diff --git a/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java b/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java index a12ce97..60bf4bd 100644 --- a/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java +++ b/components/camel-aws-mq/src/test/java/org/apache/camel/component/aws/mq/MQComponentClientRegistryTest.java @@ -20,6 +20,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; public class MQComponentClientRegistryTest extends CamelTestSupport { @@ -42,4 +44,26 @@ public class MQComponentClientRegistryTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-mq://MyQueue")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonMQClientMock awsMQClient = new AmazonMQClientMock(); + context.getRegistry().bind("awsMQClient", awsMQClient); + MQComponent component = context.getComponent("aws-mq", MQComponent.class); + MQEndpoint endpoint = (MQEndpoint) component.createEndpoint("aws-mq://MyQueue?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertNotSame(awsMQClient, endpoint.getConfiguration().getAmazonMqClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonMQClientMock awsMQClient = new AmazonMQClientMock(); + context.getRegistry().bind("awsMQClient", awsMQClient); + MQComponent component = context.getComponent("aws-mq", MQComponent.class); + MQEndpoint endpoint = (MQEndpoint) component.createEndpoint("aws-mq://MyQueue?accessKey=xxx&secretKey=yyy"); + + assertSame(awsMQClient, endpoint.getConfiguration().getAmazonMqClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMqComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMqComponentBuilderFactory.java index bac2808..8c159a6 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMqComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMqComponentBuilderFactory.java @@ -47,6 +47,21 @@ public interface AwsMqComponentBuilderFactory { */ interface AwsMqComponentBuilder extends ComponentBuilder<MQComponent> { /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default AwsMqComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type. @@ -216,6 +231,7 @@ public interface AwsMqComponentBuilderFactory { String name, Object value) { switch (name) { + case "autoDiscoverClient": getOrCreateConfiguration((MQComponent) component).setAutoDiscoverClient((boolean) value); return true; case "accessKey": getOrCreateConfiguration((MQComponent) component).setAccessKey((java.lang.String) value); return true; case "amazonMqClient": getOrCreateConfiguration((MQComponent) component).setAmazonMqClient((com.amazonaws.services.mq.AmazonMQ) value); return true; case "configuration": ((MQComponent) component).setConfiguration((org.apache.camel.component.aws.mq.MQConfiguration) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java index e7821f0..db1c9cf 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java @@ -1293,7 +1293,7 @@ public class StaticEndpointBuilders { * * @param path function */ - static org.apache.camel.builder.endpoint.dsl.Lambda2EndpointBuilderFactory.Lambda2EndpointBuilder aws2Lambda( + public static org.apache.camel.builder.endpoint.dsl.Lambda2EndpointBuilderFactory.Lambda2EndpointBuilder aws2Lambda( String path) { return org.apache.camel.builder.endpoint.dsl.Lambda2EndpointBuilderFactory.endpointBuilder("aws2-lambda", path); } @@ -1314,7 +1314,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path function */ - static org.apache.camel.builder.endpoint.dsl.Lambda2EndpointBuilderFactory.Lambda2EndpointBuilder aws2Lambda( + public static org.apache.camel.builder.endpoint.dsl.Lambda2EndpointBuilderFactory.Lambda2EndpointBuilder aws2Lambda( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.Lambda2EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -2078,7 +2078,7 @@ public class StaticEndpointBuilders { * * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.MQEndpointBuilderFactory.MQEndpointBuilder awsMq( + static org.apache.camel.builder.endpoint.dsl.MQEndpointBuilderFactory.MQEndpointBuilder awsMq( String path) { return org.apache.camel.builder.endpoint.dsl.MQEndpointBuilderFactory.endpointBuilder("aws-mq", path); } @@ -2099,7 +2099,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.MQEndpointBuilderFactory.MQEndpointBuilder awsMq( + static org.apache.camel.builder.endpoint.dsl.MQEndpointBuilderFactory.MQEndpointBuilder awsMq( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.MQEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MQEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MQEndpointBuilderFactory.java index 0020ce8..dd3bc89 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MQEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MQEndpointBuilderFactory.java @@ -38,6 +38,34 @@ public interface MQEndpointBuilderFactory { return (AdvancedMQEndpointBuilder) this; } /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default MQEndpointBuilder autoDiscoverClient(boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option will be converted to a <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default MQEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.