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 23d32b71fa6e1e7fb3cf9d40b3341ac7273f1bf1 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Fri Jul 24 14:04:11 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-MSK --- .../component/aws/msk/MSKComponentConfigurer.java | 5 ++++ .../component/aws/msk/MSKEndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws/msk/aws-msk.json | 2 ++ .../src/main/docs/aws-msk-component.adoc | 6 +++-- .../camel/component/aws/msk/MSKComponent.java | 4 +++- .../camel/component/aws/msk/MSKConfiguration.java | 15 ++++++++++++ .../aws/msk/MSKComponentClientRegistryTest.java | 24 +++++++++++++++++++ .../dsl/AwsMskComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/MSKEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 106 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKComponentConfigurer.java b/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKComponentConfigurer.java index 458bece..8f72d66 100644 --- a/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKComponentConfigurer.java +++ b/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKComponentConfigurer.java @@ -28,6 +28,8 @@ public class MSKComponentConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.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.msk.MSKConfiguration.class, value)); return true; @@ -53,6 +55,7 @@ public class MSKComponentConfigurer extends PropertyConfigurerSupport implements public Map<String, Object> getAllOptions(Object target) { Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.msk.MSKConfiguration.class); answer.put("lazyStartProducer", boolean.class); @@ -72,6 +75,8 @@ public class MSKComponentConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); + 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-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKEndpointConfigurer.java b/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKEndpointConfigurer.java index 023c584..fdd3f51 100644 --- a/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKEndpointConfigurer.java +++ b/components/camel-aws-msk/src/generated/java/org/apache/camel/component/aws/msk/MSKEndpointConfigurer.java @@ -21,6 +21,8 @@ public class MSKEndpointConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.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": @@ -46,6 +48,7 @@ public class MSKEndpointConfigurer extends PropertyConfigurerSupport implements public Map<String, Object> getAllOptions(Object target) { Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("lazyStartProducer", boolean.class); answer.put("mskClient", com.amazonaws.services.kafka.AWSKafka.class); @@ -65,6 +68,8 @@ public class MSKEndpointConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": return target.getConfiguration().getAccessKey(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "lazystartproducer": diff --git a/components/camel-aws-msk/src/generated/resources/org/apache/camel/component/aws/msk/aws-msk.json b/components/camel-aws-msk/src/generated/resources/org/apache/camel/component/aws/msk/aws-msk.json index 81a8a22..03c1fca 100644 --- a/components/camel-aws-msk/src/generated/resources/org/apache/camel/component/aws/msk/aws-msk.json +++ b/components/camel-aws-msk/src/generated/resources/org/apache/camel/component/aws/msk/aws-msk.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.msk.MSKConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry [...] "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.msk.MSKConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.msk.MSKConfiguration", "deprecated": false, "secret": false, "description": "The component configuration" }, "lazyStartProducer": { "kind": "property", "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 r [...] @@ -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.msk.MSKConfiguration", "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.msk.MSKConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registr [...] "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.msk.MSKConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "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 [...] "mskClient": { "kind": "parameter", "displayName": "Msk Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.kafka.AWSKafka", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.msk.MSKConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS MSK as client" }, diff --git a/components/camel-aws-msk/src/main/docs/aws-msk-component.adoc b/components/camel-aws-msk/src/main/docs/aws-msk-component.adoc index 215cb62..9629a2b 100644 --- a/components/camel-aws-msk/src/main/docs/aws-msk-component.adoc +++ b/components/camel-aws-msk/src/main/docs/aws-msk-component.adoc @@ -36,13 +36,14 @@ You can append query options to the URI in the following format, // component options: START -The AWS Managed Streaming for Apache Kafka (MSK) component supports 11 options, which are listed below. +The AWS Managed Streaming for Apache Kafka (MSK) 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 | *configuration* (producer) | The component configuration | | MSKConfiguration | *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 [...] @@ -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 | *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 [...] | *mskClient* (producer) | To use a existing configured AWS MSK as client | | AWSKafka diff --git a/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java b/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java index 09afbdc..4f258d0 100644 --- a/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java +++ b/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKComponent.java @@ -50,7 +50,9 @@ public class MSKComponent extends DefaultComponent { MSKConfiguration configuration = this.configuration != null ? this.configuration.copy() : new MSKConfiguration(); MSKEndpoint endpoint = new MSKEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getMskClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("Amazon msk client or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKConfiguration.java b/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKConfiguration.java index a862034..1e00742 100644 --- a/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKConfiguration.java +++ b/components/camel-aws-msk/src/main/java/org/apache/camel/component/aws/msk/MSKConfiguration.java @@ -47,6 +47,8 @@ public class MSKConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public AWSKafka getMskClient() { return mskClient; @@ -136,6 +138,19 @@ public class MSKConfiguration implements Cloneable { public void setRegion(String region) { 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-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java b/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java index 22bfa8e..d65119f 100644 --- a/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.java +++ b/components/camel-aws-msk/src/test/java/org/apache/camel/component/aws/msk/MSKComponentClientRegistryTest.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 MSKComponentClientRegistryTest extends CamelTestSupport { @@ -42,4 +44,26 @@ public class MSKComponentClientRegistryTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-msk://label")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonMSKClientMock awsMSKClient = new AmazonMSKClientMock(); + context.getRegistry().bind("awsMskClient", awsMSKClient); + MSKComponent component = context.getComponent("aws-msk", MSKComponent.class); + MSKEndpoint endpoint = (MSKEndpoint) component.createEndpoint("aws-msk://label?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertNotSame(awsMSKClient, endpoint.getConfiguration().getMskClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonMSKClientMock awsMSKClient = new AmazonMSKClientMock(); + context.getRegistry().bind("awsMskClient", awsMSKClient); + MSKComponent component = context.getComponent("aws-msk", MSKComponent.class); + MSKEndpoint endpoint = (MSKEndpoint) component.createEndpoint("aws-msk://label?accessKey=xxx&secretKey=yyy"); + + assertSame(awsMSKClient, endpoint.getConfiguration().getMskClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMskComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMskComponentBuilderFactory.java index fc34a32..3c5b0f6 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMskComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsMskComponentBuilderFactory.java @@ -47,6 +47,21 @@ public interface AwsMskComponentBuilderFactory { */ interface AwsMskComponentBuilder extends ComponentBuilder<MSKComponent> { /** + * 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 AwsMskComponentBuilder 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 AwsMskComponentBuilderFactory { String name, Object value) { switch (name) { + case "autoDiscoverClient": getOrCreateConfiguration((MSKComponent) component).setAutoDiscoverClient((boolean) value); return true; case "accessKey": getOrCreateConfiguration((MSKComponent) component).setAccessKey((java.lang.String) value); return true; case "configuration": ((MSKComponent) component).setConfiguration((org.apache.camel.component.aws.msk.MSKConfiguration) value); return true; case "lazyStartProducer": ((MSKComponent) component).setLazyStartProducer((boolean) 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 665d7fc..90049fb 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 @@ -1334,7 +1334,7 @@ public class StaticEndpointBuilders { * * @param path label */ - static org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.MQ2EndpointBuilder aws2Mq( + public static org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.MQ2EndpointBuilder aws2Mq( String path) { return org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.endpointBuilder("aws2-mq", path); } @@ -1355,7 +1355,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - static org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.MQ2EndpointBuilder aws2Mq( + public static org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.MQ2EndpointBuilder aws2Mq( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.MQ2EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -2119,7 +2119,7 @@ public class StaticEndpointBuilders { * * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.MSKEndpointBuilderFactory.MSKEndpointBuilder awsMsk( + static org.apache.camel.builder.endpoint.dsl.MSKEndpointBuilderFactory.MSKEndpointBuilder awsMsk( String path) { return org.apache.camel.builder.endpoint.dsl.MSKEndpointBuilderFactory.endpointBuilder("aws-msk", path); } @@ -2140,7 +2140,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.MSKEndpointBuilderFactory.MSKEndpointBuilder awsMsk( + static org.apache.camel.builder.endpoint.dsl.MSKEndpointBuilderFactory.MSKEndpointBuilder awsMsk( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.MSKEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MSKEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MSKEndpointBuilderFactory.java index dfa1f13..ad4375b 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MSKEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MSKEndpointBuilderFactory.java @@ -39,6 +39,34 @@ public interface MSKEndpointBuilderFactory { return (AdvancedMSKEndpointBuilder) 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 MSKEndpointBuilder 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 MSKEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.