You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/03/28 15:07:29 UTC
[3/5] camel git commit: CAMEL-11082: camel-consul : make it easy to
configure components and service-discovery in spring-boot
CAMEL-11082: camel-consul : make it easy to configure components and service-discovery in spring-boot
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6f4fdf9e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6f4fdf9e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6f4fdf9e
Branch: refs/heads/master
Commit: 6f4fdf9e05f437a1f2d7a608131ceda55f28deb9
Parents: ea3a02e
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 28 14:27:47 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Mar 28 17:06:47 2017 +0200
----------------------------------------------------------------------
...erviceCallServiceDiscoveryConfiguration.java | 24 +-
.../src/main/docs/consul-component.adoc | 19 +-
.../camel/component/consul/ConsulComponent.java | 127 +++++--
.../component/consul/ConsulConfiguration.java | 50 ++-
.../camel/component/consul/ConsulEndpoint.java | 26 +-
.../consul/cloud/ConsulServiceDiscovery.java | 10 +-
.../cloud/ConsulServiceDiscoveryFactory.java | 19 +-
.../src/main/resources/application.properties | 8 +-
.../ConsulComponentAutoConfiguration.java | 34 +-
.../ConsulComponentConfiguration.java | 333 +++++++++++++++++++
.../cloud/ConsulCloudAutoConfiguration.java | 105 ------
.../cloud/ConsulCloudConfiguration.java | 53 ---
...ConsulServiceDiscoveryAutoConfiguration.java | 106 ++++++
.../main/resources/META-INF/spring.factories | 2 +-
.../ConsulServiceDiscoveryDisabledTest.java | 64 ++++
.../ConsulServiceDiscoveryEnabledTest.java | 65 ++++
.../src/test/resources/logback.xml | 39 +++
...CallServiceDiscoveryConfigurationCommon.java | 150 +++++++++
...ServiceDiscoveryConfigurationProperties.java | 48 +++
...ystrixConfigurationDefinitionProperties.java | 2 +-
.../SpringBootAutoConfigurationMojo.java | 28 +-
21 files changed, 1091 insertions(+), 221 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
index b30f871..bd7d27e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
@@ -32,7 +32,7 @@ public class ConsulServiceCallServiceDiscoveryConfiguration extends ServiceCallS
@XmlAttribute
private String url;
@XmlAttribute
- private String dc;
+ private String datacenter;
@XmlAttribute @Metadata(label = "security")
private String aclToken;
@XmlAttribute @Metadata(label = "security")
@@ -73,15 +73,33 @@ public class ConsulServiceCallServiceDiscoveryConfiguration extends ServiceCallS
this.url = url;
}
+ /**
+ * @deprecated replaced by {@link #getDatacenter()} ()}
+ */
+ @Deprecated
public String getDc() {
- return dc;
+ return datacenter;
}
/**
* The data center
+ *
+ * @deprecated replaced by {@link #setDatacenter(String)} ()}
*/
+ @Deprecated
public void setDc(String dc) {
- this.dc = dc;
+ this.datacenter = dc;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ /**
+ * The data center
+ */
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
}
public String getAclToken() {
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/docs/consul-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/docs/consul-component.adoc b/components/camel-consul/src/main/docs/consul-component.adoc
index 8c8823f..9d7080f 100644
--- a/components/camel-consul/src/main/docs/consul-component.adoc
+++ b/components/camel-consul/src/main/docs/consul-component.adoc
@@ -35,7 +35,22 @@ You can append query options to the URI in the following format:
// component options: START
-The Consul component has no options.
+The Consul component supports 8 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|=======================================================================
+| Name | Description | Default | Type
+| **url** (common) | The Consul agent URL | | String
+| **datacenter** (common) | The data center | | String
+| **sslContextParameters** (common) | SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters instance. | | SSLContextParameters
+| **aclToken** (common) | Sets the ACL token to be used with Consul | | String
+| **userName** (common) | Sets the username to be used for basic authentication | | String
+| **password** (common) | Sets the password to be used for basic authentication | | String
+| **configuration** (advanced) | Sets the common configuration shared among endpoints | | ConsulConfiguration
+| **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
+|=======================================================================
// component options: END
@@ -64,7 +79,6 @@ with the following path and query parameters:
|=======================================================================
| Name | Description | Default | Type
| **connectTimeoutMillis** (common) | Connect timeout for OkHttpClient | | Long
-| **dc** (common) | The data center | | String
| **key** (common) | The default key. Can be overridden by CamelConsulKey | | String
| **pingInstance** (common) | Configure if the AgentClient should attempt a ping before returning the Consul instance | true | boolean
| **readTimeoutMillis** (common) | Read timeout for OkHttpClient | | Long
@@ -76,6 +90,7 @@ with the following path and query parameters:
| **exchangePattern** (consumer) | Sets the exchange pattern when the consumer creates an exchange. | | ExchangePattern
| **action** (producer) | The default action. Can be overridden by CamelConsulAction | | String
| **valueAsString** (producer) | Default to transform values retrieved from Consul i.e. on KV endpoint to string. | false | boolean
+| **datacenter** (advanced) | The data center | | String
| **synchronous** (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
| **blockSeconds** (watch) | The second to wait for a watch event default 10 seconds | 10 | Integer
| **firstIndex** (watch) | The first index for watch for default 0 | 0 | long
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
index 83887e3..ccacf8a 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.consul;
import java.util.Map;
+import java.util.Optional;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
@@ -25,53 +26,137 @@ import org.apache.camel.component.consul.enpoint.ConsulEventConsumer;
import org.apache.camel.component.consul.enpoint.ConsulEventProducer;
import org.apache.camel.component.consul.enpoint.ConsulKeyValueConsumer;
import org.apache.camel.component.consul.enpoint.ConsulKeyValueProducer;
-import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.jsse.SSLContextParameters;
/**
* Represents the component that manages {@link ConsulEndpoint}.
*/
-public class ConsulComponent extends UriEndpointComponent {
+public class ConsulComponent extends DefaultComponent {
+
+ @Metadata(label = "advanced")
+ private ConsulConfiguration configuration = new ConsulConfiguration();
public ConsulComponent() {
- super(ConsulEndpoint.class);
+ super();
}
public ConsulComponent(CamelContext context) {
- super(context, ConsulEndpoint.class);
+ super(context);
+ }
+
+ // ************************************
+ // Options
+ // ************************************
+
+
+ public String getUrl() {
+ return this.configuration.getUrl();
+ }
+
+ /**
+ * The Consul agent URL
+ */
+ public void setUrl(String url) {
+ this.configuration.setUrl(url);
+ }
+
+ public String getDatacenter() {
+ return configuration.getDatacenter();
+ }
+
+ /**
+ * The data center
+ * @param datacenter
+ */
+ public void setDatacenter(String datacenter) {
+ configuration.setDatacenter(datacenter);
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return configuration.getSslContextParameters();
+ }
+
+ /**
+ * SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters
+ * instance.
+ * @param sslContextParameters
+ */
+ public void setSslContextParameters(SSLContextParameters sslContextParameters) {
+ configuration.setSslContextParameters(sslContextParameters);
+ }
+
+ public String getAclToken() {
+ return configuration.getAclToken();
+ }
+
+ /**
+ * Sets the ACL token to be used with Consul
+ * @param aclToken
+ */
+ public void setAclToken(String aclToken) {
+ configuration.setAclToken(aclToken);
+ }
+
+ public String getUserName() {
+ return configuration.getUserName();
+ }
+
+ /**
+ * Sets the username to be used for basic authentication
+ * @param userName
+ */
+ public void setUserName(String userName) {
+ configuration.setUserName(userName);
+ }
+
+ public String getPassword() {
+ return configuration.getPassword();
+ }
+
+ /**
+ * Sets the password to be used for basic authentication
+ * @param password
+ */
+ public void setPassword(String password) {
+ configuration.setPassword(password);
}
+ public ConsulConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * Sets the common configuration shared among endpoints
+ */
+ public void setConfiguration(ConsulConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- return ConsulApiEndpoint.valueOf(remaining).create(
- remaining,
- uri,
- this,
- createConfiguration(parameters)
- );
- }
+ ConsulConfiguration configuration = Optional.ofNullable(this.configuration).orElseGet(ConsulConfiguration::new).copy();
+ configuration.setCamelContext(getCamelContext());
- private ConsulConfiguration createConfiguration(Map<String, Object> parameters) throws Exception {
- ConsulConfiguration configuration = new ConsulConfiguration(getCamelContext());
setProperties(configuration, parameters);
- return configuration;
+ return ConsulApiEndpoint.valueOf(remaining).create(remaining, uri, this, configuration);
}
- // *************************************************************************
// Consul Api Enpoints (see https://www.consul.io/docs/agent/http.html)
- // *************************************************************************
-
private enum ConsulApiEndpoint {
kv(ConsulKeyValueProducer::new, ConsulKeyValueConsumer::new),
event(ConsulEventProducer::new, ConsulEventConsumer::new),
agent(ConsulAgentProducer::new, null);
- private final ConsulEndpoint.ProducerFactory producerFactory;
- private final ConsulEndpoint.ConsumerFactory consumerFactory;
+ private final Optional<ConsulEndpoint.ProducerFactory> producerFactory;
+ private final Optional<ConsulEndpoint.ConsumerFactory> consumerFactory;
ConsulApiEndpoint(ConsulEndpoint.ProducerFactory producerFactory, ConsulEndpoint.ConsumerFactory consumerFactory) {
- this.producerFactory = producerFactory;
- this.consumerFactory = consumerFactory;
+ this.producerFactory = Optional.ofNullable(producerFactory);
+ this.consumerFactory = Optional.ofNullable(consumerFactory);
}
public Endpoint create(String apiEndpoint, String uri, ConsulComponent component, ConsulConfiguration configuration) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
index dbf1466..34fa757 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
@@ -22,17 +22,19 @@ import java.util.Set;
import com.orbitz.consul.Consul;
import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.jsse.SSLContextParameters;
@UriParams
-public class ConsulConfiguration {
+public class ConsulConfiguration implements CamelContextAware, Cloneable {
@UriParam
private String url;
- @UriParam
- private String dc;
+ @UriParam(label = "advanced")
+ private String datacenter;
@UriParam(javaType = "java.lang.String")
private Set<String> tags;
@@ -68,7 +70,7 @@ public class ConsulConfiguration {
@UriParam(label = "consumer,watch", defaultValue = "false")
private boolean recursive;
- private final CamelContext context;
+ private CamelContext context;
public ConsulConfiguration() {
this.context = null;
@@ -78,8 +80,14 @@ public class ConsulConfiguration {
this.context = context;
}
- public CamelContext getContext() {
- return this.context;
+ @Override
+ public void setCamelContext(CamelContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return context;
}
public String getUrl() {
@@ -93,15 +101,33 @@ public class ConsulConfiguration {
this.url = url;
}
+ /**
+ * @deprecated replaced by {@link #getDatacenter()} ()}
+ */
+ @Deprecated
public String getDc() {
- return dc;
+ return datacenter;
}
/**
* The data center
+ *
+ * @deprecated replaced by {@link #setDatacenter(String)} ()}
*/
+ @Deprecated
public void setDc(String dc) {
- this.dc = dc;
+ this.datacenter = dc;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ /**
+ * The data center
+ */
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
}
public Set<String> getTags() {
@@ -311,4 +337,12 @@ public class ConsulConfiguration {
return builder.build();
}
+
+ public ConsulConfiguration copy() {
+ try {
+ return (ConsulConfiguration)super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
index b17177c..0399830 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.consul;
+import java.util.Optional;
+
import com.orbitz.consul.Consul;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
@@ -41,8 +43,8 @@ public class ConsulEndpoint extends DefaultEndpoint {
@Metadata(required = "true")
private final String apiEndpoint;
- private final ProducerFactory producerFactory;
- private final ConsumerFactory consumerFactory;
+ private final Optional<ProducerFactory> producerFactory;
+ private final Optional<ConsumerFactory> consumerFactory;
private Consul consul;
@@ -51,8 +53,8 @@ public class ConsulEndpoint extends DefaultEndpoint {
String uri,
ConsulComponent component,
ConsulConfiguration configuration,
- ProducerFactory producerFactory,
- ConsumerFactory consumerFactory) {
+ Optional<ProducerFactory> producerFactory,
+ Optional<ConsumerFactory> consumerFactory) {
super(uri, component);
@@ -69,20 +71,20 @@ public class ConsulEndpoint extends DefaultEndpoint {
@Override
public Producer createProducer() throws Exception {
- if (producerFactory == null) {
- throw new IllegalArgumentException("No producer for " + apiEndpoint);
- }
+ ProducerFactory factory = producerFactory.orElseThrow(
+ () -> new IllegalArgumentException("No producer for " + apiEndpoint)
+ );
- return producerFactory.create(this, configuration);
+ return factory.create(this, configuration);
}
@Override
public Consumer createConsumer(Processor processor) throws Exception {
- if (consumerFactory == null) {
- throw new IllegalArgumentException("No consumer for " + apiEndpoint);
- }
+ ConsumerFactory factory = consumerFactory.orElseThrow(
+ () -> new IllegalArgumentException("No consumer for " + apiEndpoint)
+ );
- return consumerFactory.create(this, configuration, processor);
+ return factory.create(this, configuration, processor);
}
// *************************************************************************
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
index c09d211..fd3fe60 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
@@ -36,17 +36,15 @@ import org.apache.camel.impl.cloud.DefaultServiceHealth;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.function.Suppliers;
-;
-
public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
private final Supplier<Consul> client;
private final CatalogOptions catalogOptions;
public ConsulServiceDiscovery(ConsulConfiguration configuration) throws Exception {
- this.client = Suppliers.memorize(configuration::createConsulClient, e -> { throw new RuntimeCamelException(e); });
+ this.client = Suppliers.memorize(configuration::createConsulClient, this::rethrowAsRuntimeCamelException);
ImmutableCatalogOptions.Builder builder = ImmutableCatalogOptions.builder();
- ObjectHelper.ifNotEmpty(configuration.getDc(), builder::datacenter);
+ ObjectHelper.ifNotEmpty(configuration.getDatacenter(), builder::datacenter);
ObjectHelper.ifNotEmpty(configuration.getTags(), tags -> tags.forEach(builder::tag));
catalogOptions = builder.build();
@@ -70,6 +68,10 @@ public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
// Helpers
// *************************
+ private void rethrowAsRuntimeCamelException(Exception e) {
+ throw new RuntimeCamelException(e);
+ }
+
private boolean isHealthy(ServiceHealth serviceHealth) {
return serviceHealth.getChecks().stream().allMatch(
check -> ObjectHelper.equal(check.getStatus(), "passing", true)
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
index 04215ef..0c032af 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
@@ -45,14 +45,31 @@ public class ConsulServiceDiscoveryFactory implements ServiceDiscoveryFactory {
configuration.setUrl(url);
}
+ /**
+ * @deprecated, @deprecated replaced by {@link #getDatacenter()} ()}
+ * @return
+ */
+ @Deprecated
public String getDc() {
- return configuration.getDc();
+ return configuration.getDatacenter();
}
+ /**
+ * @deprecated, @deprecated replaced by {@link #setDatacenter(String)}} ()}
+ */
+ @Deprecated
public void setDc(String dc) {
configuration.setDc(dc);
}
+ public void setDatacenter(String dc) {
+ configuration.setDatacenter(dc);
+ }
+
+ public String getDatacenter() {
+ return configuration.getDatacenter();
+ }
+
public SSLContextParameters getSslContextParameters() {
return configuration.getSslContextParameters();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties b/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
index bfe3682..6684b24 100644
--- a/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
@@ -13,4 +13,10 @@ camel.rest.binding-mode=auto
camel.cloud.service-filter.blacklist[service-1] = localhost:9012
# Configure additional services
-camel.cloud.service-discovery.services[service-2] = localhost:9021,localhost:9022,localhost:9023
\ No newline at end of file
+camel.cloud.service-discovery.services[service-2] = localhost:9021,localhost:9022,localhost:9023
+
+# Consul
+#
+# this property is not mandatory and it has been included to show how to configure
+# the service discovery implementation provided by camel-consul
+camel.cloud.consul.service-discovery.url=http://localhost:8500
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
index 1ddca31..cd7fbbf 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
@@ -16,8 +16,11 @@
*/
package org.apache.camel.component.consul.springboot;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.component.consul.ConsulComponent;
+import org.apache.camel.util.IntrospectionSupport;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -26,6 +29,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.bind.RelaxedPropertyResolver;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
@@ -40,16 +44,42 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration")
@Conditional(ConsulComponentAutoConfiguration.Condition.class)
@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+@EnableConfigurationProperties(ConsulComponentConfiguration.class)
public class ConsulComponentAutoConfiguration {
@Lazy
@Bean(name = "consul-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(ConsulComponent.class)
- public ConsulComponent configureConsulComponent(CamelContext camelContext)
- throws Exception {
+ public ConsulComponent configureConsulComponent(CamelContext camelContext,
+ ConsulComponentConfiguration configuration) throws Exception {
ConsulComponent component = new ConsulComponent();
component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ IntrospectionSupport.setProperties(camelContext,
+ camelContext.getTypeConverter(), nestedProperty,
+ nestedParameters);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ IntrospectionSupport.setProperties(camelContext,
+ camelContext.getTypeConverter(), component, parameters);
return component;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
index 19877ec..519a1b6 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
@@ -16,7 +16,12 @@
*/
package org.apache.camel.component.consul.springboot;
+import java.util.Set;
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.jsse.SSLContextParameters;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* The camel consul component allows you to work with Consul a distributed
@@ -28,12 +33,100 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class ConsulComponentConfiguration {
/**
+ * The Consul agent URL
+ */
+ private String url;
+ /**
+ * The data center
+ */
+ private String datacenter;
+ /**
+ * SSL configuration using an
+ * org.apache.camel.util.jsse.SSLContextParameters instance.
+ */
+ @NestedConfigurationProperty
+ private SSLContextParameters sslContextParameters;
+ /**
+ * Sets the ACL token to be used with Consul
+ */
+ private String aclToken;
+ /**
+ * Sets the username to be used for basic authentication
+ */
+ private String userName;
+ /**
+ * Sets the password to be used for basic authentication
+ */
+ private String password;
+ /**
+ * Sets the common configuration shared among endpoints
+ */
+ private ConsulConfigurationNestedConfiguration configuration;
+ /**
* Whether the component should resolve property placeholders on itself when
* starting. Only properties which are of String type can use property
* placeholders.
*/
private Boolean resolvePropertyPlaceholders = true;
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return sslContextParameters;
+ }
+
+ public void setSslContextParameters(
+ SSLContextParameters sslContextParameters) {
+ this.sslContextParameters = sslContextParameters;
+ }
+
+ public String getAclToken() {
+ return aclToken;
+ }
+
+ public void setAclToken(String aclToken) {
+ this.aclToken = aclToken;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public ConsulConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ ConsulConfigurationNestedConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
@@ -42,4 +135,244 @@ public class ConsulComponentConfiguration {
Boolean resolvePropertyPlaceholders) {
this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
}
+
+ public static class ConsulConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.consul.ConsulConfiguration.class;
+ private CamelContext camelContext;
+ /**
+ * The Consul agent URL
+ */
+ private String url;
+ /**
+ * The data center
+ *
+ * @deprecated replaced by {@link #setDatacenter(String)} ()}
+ */
+ @Deprecated
+ private String dc;
+ /**
+ * The data center
+ */
+ private String datacenter;
+ /**
+ * Set tags. You can separate multiple tags by comma.
+ */
+ private Set tags;
+ /**
+ * SSL configuration using an
+ * org.apache.camel.util.jsse.SSLContextParameters instance.
+ */
+ @NestedConfigurationProperty
+ private SSLContextParameters sslContextParameters;
+ /**
+ * Sets the ACL token to be used with Consul
+ */
+ private String aclToken;
+ /**
+ * The default action. Can be overridden by CamelConsulAction
+ */
+ private String action;
+ /**
+ * Sets the username to be used for basic authentication
+ */
+ private String userName;
+ /**
+ * Sets the password to be used for basic authentication
+ */
+ private String password;
+ /**
+ * Connect timeout for OkHttpClient
+ */
+ private Long connectTimeoutMillis;
+ /**
+ * Read timeout for OkHttpClient
+ */
+ private Long readTimeoutMillis;
+ /**
+ * Write timeout for OkHttpClient
+ */
+ private Long writeTimeoutMillis;
+ /**
+ * Configure if the AgentClient should attempt a ping before returning
+ * the Consul instance
+ */
+ private Boolean pingInstance = true;
+ /**
+ * Default to transform values retrieved from Consul i.e. on KV endpoint
+ * to string.
+ */
+ private Boolean valueAsString = false;
+ /**
+ * The default key. Can be overridden by CamelConsulKey
+ */
+ private String key;
+ /**
+ * The second to wait for a watch event, default 10 seconds
+ */
+ private Integer blockSeconds = 10;
+ /**
+ * The first index for watch for, default 0
+ */
+ private Long firstIndex = 0L;
+ /**
+ * Recursively watch, default false
+ */
+ private Boolean recursive = false;
+
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @Deprecated
+ @DeprecatedConfigurationProperty
+ public String getDc() {
+ return dc;
+ }
+
+ @Deprecated
+ public void setDc(String dc) {
+ this.dc = dc;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
+ }
+
+ public Set getTags() {
+ return tags;
+ }
+
+ public void setTags(Set tags) {
+ this.tags = tags;
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return sslContextParameters;
+ }
+
+ public void setSslContextParameters(
+ SSLContextParameters sslContextParameters) {
+ this.sslContextParameters = sslContextParameters;
+ }
+
+ public String getAclToken() {
+ return aclToken;
+ }
+
+ public void setAclToken(String aclToken) {
+ this.aclToken = aclToken;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public Long getConnectTimeoutMillis() {
+ return connectTimeoutMillis;
+ }
+
+ public void setConnectTimeoutMillis(Long connectTimeoutMillis) {
+ this.connectTimeoutMillis = connectTimeoutMillis;
+ }
+
+ public Long getReadTimeoutMillis() {
+ return readTimeoutMillis;
+ }
+
+ public void setReadTimeoutMillis(Long readTimeoutMillis) {
+ this.readTimeoutMillis = readTimeoutMillis;
+ }
+
+ public Long getWriteTimeoutMillis() {
+ return writeTimeoutMillis;
+ }
+
+ public void setWriteTimeoutMillis(Long writeTimeoutMillis) {
+ this.writeTimeoutMillis = writeTimeoutMillis;
+ }
+
+ public Boolean getPingInstance() {
+ return pingInstance;
+ }
+
+ public void setPingInstance(Boolean pingInstance) {
+ this.pingInstance = pingInstance;
+ }
+
+ public Boolean getValueAsString() {
+ return valueAsString;
+ }
+
+ public void setValueAsString(Boolean valueAsString) {
+ this.valueAsString = valueAsString;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Integer getBlockSeconds() {
+ return blockSeconds;
+ }
+
+ public void setBlockSeconds(Integer blockSeconds) {
+ this.blockSeconds = blockSeconds;
+ }
+
+ public Long getFirstIndex() {
+ return firstIndex;
+ }
+
+ public void setFirstIndex(Long firstIndex) {
+ this.firstIndex = firstIndex;
+ }
+
+ public Boolean getRecursive() {
+ return recursive;
+ }
+
+ public void setRecursive(Boolean recursive) {
+ this.recursive = recursive;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
deleted file mode 100644
index 22fb21a..0000000
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.consul.springboot.cloud;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.PostConstruct;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.component.consul.ConsulConfiguration;
-import org.apache.camel.component.consul.cloud.ConsulServiceDiscoveryFactory;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.util.IntrospectionSupport;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-
-@Configuration
-@ConditionalOnBean({ CamelAutoConfiguration.class, CamelContext.class })
-@Conditional(ConsulCloudAutoConfiguration.Condition.class)
-@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties(ConsulCloudConfiguration.class)
-public class ConsulCloudAutoConfiguration {
- @Autowired
- private CamelContext camelContext;
- @Autowired
- private ConsulCloudConfiguration configuration;
- @Autowired
- private ConfigurableBeanFactory beanFactory;
-
- @Lazy
- @Bean(name = "consul-service-discovery")
- public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception {
- ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
-
- IntrospectionSupport.setProperties(
- camelContext,
- camelContext.getTypeConverter(),
- factory,
- IntrospectionSupport.getNonNullProperties(configuration));
-
- return factory.newInstance(camelContext);
- }
-
- @PostConstruct
- public void postConstruct() {
- if (beanFactory != null) {
- ConsulCloudConfiguration.ServiceDiscoveryConfiguration discovery = configuration.getServiceDiscovery();
- Map<String, Object> parameters = new HashMap<>();
-
- for (Map.Entry<String, ConsulConfiguration> entry : discovery.getConfigurations().entrySet()) {
- // clean up params
- parameters.clear();
-
- // The instance factory
- ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
-
- try {
- IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
- IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
-
- beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
- } catch (Exception e) {
- throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
- }
- }
- }
- }
-
- // *******************************
- // Condition
- // *******************************
-
- public static class Condition extends GroupCondition {
- public Condition() {
- super(
- "camel.cloud",
- "camel.cloud.consul"
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
deleted file mode 100644
index da94b19..0000000
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.consul.springboot.cloud;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.component.consul.ConsulConfiguration;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.cloud.consul")
-public class ConsulCloudConfiguration {
- private boolean enabled = true;
- private ServiceDiscoveryConfiguration serviceDiscovery = new ServiceDiscoveryConfiguration();
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public ServiceDiscoveryConfiguration getServiceDiscovery() {
- return serviceDiscovery;
- }
-
- // *************************************************************************
- //
- // *************************************************************************
-
- public class ServiceDiscoveryConfiguration extends ConsulConfiguration {
- private final Map<String, ConsulConfiguration> configurations = new HashMap<>();
-
- public Map<String, ConsulConfiguration> getConfigurations() {
- return configurations;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java
new file mode 100644
index 0000000..ec4e9d3
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.consul.springboot.cloud;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.component.consul.cloud.ConsulServiceDiscoveryFactory;
+import org.apache.camel.component.consul.springboot.ConsulComponentConfiguration;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationCommon;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.util.IntrospectionSupport;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+@Configuration
+@ConditionalOnBean({ CamelAutoConfiguration.class, CamelContext.class })
+@Conditional(ConsulServiceDiscoveryAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(ConsulServiceCallServiceDiscoveryConfigurationProperties.class)
+public class ConsulServiceDiscoveryAutoConfiguration {
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private ConsulServiceCallServiceDiscoveryConfigurationProperties configuration;
+ @Autowired
+ private ConfigurableBeanFactory beanFactory;
+
+ @Lazy
+ @Bean(name = "consul-service-discovery")
+ public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception {
+ ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
+
+ IntrospectionSupport.setProperties(
+ camelContext,
+ camelContext.getTypeConverter(),
+ factory,
+ IntrospectionSupport.getNonNullProperties(configuration));
+
+ return factory.newInstance(camelContext);
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ if (beanFactory != null) {
+ Map<String, Object> parameters = new HashMap<>();
+
+ for (Map.Entry<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
+ // clean up params
+ parameters.clear();
+
+ // The instance factory
+ ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
+
+ try {
+ IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
+ IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
+
+ beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
+ } catch (Exception e) {
+ throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class Condition extends GroupCondition {
+ public Condition() {
+ super(
+ "camel.cloud.consul",
+ "camel.cloud.consul.service-discovery"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
index 4517ac3..fcc6bf8 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
@@ -17,4 +17,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.camel.component.consul.springboot.ConsulComponentAutoConfiguration,\
-org.apache.camel.component.consul.springboot.cloud.ConsulCloudAutoConfiguration
+org.apache.camel.component.consul.springboot.cloud.ConsulServiceDiscoveryAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
new file mode 100644
index 0000000..01cc252
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.consul.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+ classes = {
+ ConsulServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.consul.service-discovery.enabled=false"
+})
+public class ConsulServiceDiscoveryDisabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertTrue(beans.isEmpty());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertFalse(beans.containsKey("consul-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
new file mode 100644
index 0000000..cedfde5
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.consul.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+ classes = {
+ ConsulServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.consul.service-discovery.enabled=true"
+})
+public class ConsulServiceDiscoveryEnabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertEquals(1, beans.size());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertTrue(beans.containsKey("consul-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml
new file mode 100644
index 0000000..93d5a0c
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%-15.15thread] %-5level %-30.30logger - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%-15.15thread] %-5level %-30.30logger - %msg%n</pattern>
+ </encoder>
+ <file>target/camel-consul-starter-test.log</file>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="FILE"/>
+ </root>
+
+</configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
new file mode 100644
index 0000000..23df276
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
@@ -0,0 +1,150 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.cloud.springboot;
+
+import java.util.List;
+import org.apache.camel.model.PropertyDefinition;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+public class ConsulServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * The Consul agent URL
+ */
+ private String url;
+ /**
+ * The data center
+ */
+ private String datacenter;
+ /**
+ * Sets the ACL token to be used with Consul
+ */
+ private String aclToken;
+ /**
+ * Sets the username to be used for basic authentication
+ */
+ private String userName;
+ /**
+ * Sets the password to be used for basic authentication
+ */
+ private String password;
+ /**
+ * Connect timeout for OkHttpClient
+ */
+ private Long connectTimeoutMillis;
+ /**
+ * Read timeout for OkHttpClient
+ */
+ private Long readTimeoutMillis;
+ /**
+ * Write timeout for OkHttpClient
+ */
+ private Long writeTimeoutMillis;
+ /**
+ * The seconds to wait for a watch event default 10 seconds
+ */
+ private Integer blockSeconds = 10;
+ /**
+ * Set client properties to use. These properties are specific to what
+ * service call implementation are in use. For example if using ribbon then
+ * the client properties are define in
+ * com.netflix.client.config.CommonClientConfigKey.
+ */
+ private List<PropertyDefinition> properties;
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
+ }
+
+ public String getAclToken() {
+ return aclToken;
+ }
+
+ public void setAclToken(String aclToken) {
+ this.aclToken = aclToken;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public Long getConnectTimeoutMillis() {
+ return connectTimeoutMillis;
+ }
+
+ public void setConnectTimeoutMillis(Long connectTimeoutMillis) {
+ this.connectTimeoutMillis = connectTimeoutMillis;
+ }
+
+ public Long getReadTimeoutMillis() {
+ return readTimeoutMillis;
+ }
+
+ public void setReadTimeoutMillis(Long readTimeoutMillis) {
+ this.readTimeoutMillis = readTimeoutMillis;
+ }
+
+ public Long getWriteTimeoutMillis() {
+ return writeTimeoutMillis;
+ }
+
+ public void setWriteTimeoutMillis(Long writeTimeoutMillis) {
+ this.writeTimeoutMillis = writeTimeoutMillis;
+ }
+
+ public Integer getBlockSeconds() {
+ return blockSeconds;
+ }
+
+ public void setBlockSeconds(Integer blockSeconds) {
+ this.blockSeconds = blockSeconds;
+ }
+
+ public List<PropertyDefinition> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(List<PropertyDefinition> properties) {
+ this.properties = properties;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java
new file mode 100644
index 0000000..57d2588
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.cloud.springboot;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud.consul.service-discovery")
+public class ConsulServiceCallServiceDiscoveryConfigurationProperties
+ extends
+ ConsulServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * Enable the component
+ */
+ private boolean enabled = true;
+ /**
+ * Define additional configuration definitions
+ */
+ private Map<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> configurations = new HashMap<>();
+
+ public Map<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> getConfigurations() {
+ return configurations;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
index 0daa611..5cf7c99 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
@@ -26,7 +26,7 @@ public class HystrixConfigurationDefinitionProperties
HystrixConfigurationDefinitionCommon {
/**
- * Enable camel-hystrix
+ * Enable the component
*/
private boolean enabled = true;
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
index 0ffa9a4..7b96fb0 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
@@ -196,8 +196,10 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
private void executeModels() throws MojoExecutionException, MojoFailureException {
final Set<File> files = PackageHelper.findJsonFiles(buildDir, p -> p.isDirectory() || p.getName().endsWith(".json"));
+ String json;
+
// Hystrix
- final String json = loadModelJson(files, "hystrixConfiguration");
+ json = loadModelJson(files, "hystrixConfiguration");
if (json != null) {
OtherModel model = generateOtherModel(json);
@@ -205,11 +207,23 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration happens in camel-hystrix-starter
- createHystrixConfigurationSource(pkg, model);
+ createHystrixConfigurationSource(pkg, model, "camel.hystrix");
+ }
+
+ // Consul
+ json = loadModelJson(files, "consulServiceDiscovery");
+ if (json != null) {
+ OtherModel model = generateOtherModel(json);
+
+ int pos = model.getJavaType().lastIndexOf(".");
+ String pkg = model.getJavaType().substring(0, pos) + ".springboot";
+
+ // Generate properties, auto-configuration happens in camel-consul-starter
+ createHystrixConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery");
}
}
- private void createHystrixConfigurationSource(String packageName, OtherModel model) throws MojoFailureException {
+ private void createHystrixConfigurationSource(String packageName, OtherModel model, String propertiesPrefix) throws MojoFailureException {
final int pos = model.getJavaType().lastIndexOf(".");
final String commonName = model.getJavaType().substring(pos + 1) + "Common";
final String configName = model.getJavaType().substring(pos + 1) + "Properties";
@@ -229,8 +243,8 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String type = option.getJavaType();
String name = option.getName();
- if ("id".equalsIgnoreCase(name) || "parent".equalsIgnoreCase(name)) {
- // Skip it as it should not be set via spring boot
+ if ("id".equalsIgnoreCase(name) || "parent".equalsIgnoreCase(name) || "camelContext".equalsIgnoreCase(name)) {
+ // Skip them as they should not be set via spring boot
continue;
}
@@ -261,7 +275,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
configClass.setPackage(packageName);
configClass.setName(configName);
configClass.extendSuperType(commonClass);
- configClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", "camel.hystrix");
+ configClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", propertiesPrefix);
configClass.addImport(Map.class);
configClass.addImport(HashMap.class);
configClass.removeImport(commonClass);
@@ -271,7 +285,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
.setType(boolean.class)
.setPrivate()
.setLiteralInitializer("true")
- .getJavaDoc().setFullText("Enable camel-hystrix");
+ .getJavaDoc().setFullText("Enable the component");
configClass.addField("Map<String, " + commonName + "> configurations = new HashMap<>()")
.setPrivate()
.getJavaDoc().setFullText("Define additional configuration definitions");