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/02/21 11:17:50 UTC
[1/2] camel git commit: CAMEL-10686: service-call eip : generate
service-call auto configurations for spring-boot
Repository: camel
Updated Branches:
refs/heads/master 2c3fa6c4b -> 615314557
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java
new file mode 100644
index 0000000..3d2d7b7
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java
@@ -0,0 +1,45 @@
+/**
+ * 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.dns.springboot.cloud;
+
+import org.apache.camel.component.dns.DnsConfiguration;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud.dns")
+public class DnsCloudConfiguration {
+ 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 DnsConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories
index fef7327..f078ff9 100644
--- a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,5 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.dns.springboot.DnsComponentAutoConfiguration
+org.apache.camel.component.dns.springboot.DnsComponentAutoConfiguration,\
+org.apache.camel.component.dns.springboot.cloud.DnsCloudAutoConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
new file mode 100644
index 0000000..9af3218
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
@@ -0,0 +1,83 @@
+/**
+ * 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.etcd.springboot.cloud;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.component.etcd.cloud.EtcdOnDemandServiceDiscovery;
+import org.apache.camel.component.etcd.cloud.EtcdServiceDiscoveryFactory;
+import org.apache.camel.component.etcd.cloud.EtcdWatchServiceDiscovery;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionMessage;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+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;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+@Configuration
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@Conditional(EtcdCloudAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(EtcdCloudConfiguration.class)
+public class EtcdCloudAutoConfiguration {
+ @Lazy
+ @Bean(name = "etcd-service-discovery")
+ @ConditionalOnClass(CamelContext.class)
+ public ServiceDiscovery configureServiceDiscoveryFactory(CamelContext camelContext, EtcdCloudConfiguration configuration) throws Exception {
+ EtcdServiceDiscoveryFactory factory = new EtcdServiceDiscoveryFactory();
+
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null, false);
+ IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
+
+ return factory.newInstance(camelContext);
+ }
+
+ public static class Condition extends SpringBootCondition {
+ @Override
+ public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
+ boolean groupEnabled = isEnabled(conditionContext, "camel.cloud.", true);
+
+ ConditionMessage.Builder message = ConditionMessage.forCondition("camel.cloud.etcd");
+ if (isEnabled(conditionContext, "camel.cloud.etcd.", groupEnabled)) {
+ return ConditionOutcome.match(message.because("enabled"));
+ }
+
+ return ConditionOutcome.noMatch(message.because("not enabled"));
+ }
+
+ private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) {
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix);
+ return resolver.getProperty("enabled", Boolean.class, defaultValue);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
new file mode 100644
index 0000000..42d4e92
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
@@ -0,0 +1,54 @@
+/**
+ * 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.etcd.springboot.cloud;
+
+import org.apache.camel.component.etcd.EtcdConfiguration;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud.etcd")
+public class EtcdCloudConfiguration {
+ 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 EtcdConfiguration {
+ private String type;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories
index d3e9b9a..1358d3e 100644
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,5 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.etcd.springboot.EtcdComponentAutoConfiguration
+org.apache.camel.component.etcd.springboot.EtcdComponentAutoConfiguration,\
+org.apache.camel.component.etcd.springboot.cloud.EtcdCloudAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
new file mode 100644
index 0000000..6527ba4
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
@@ -0,0 +1,79 @@
+/**
+ * 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.kubernetes.springboot.cloud;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.component.kubernetes.cloud.KubernetesServiceDiscoveryFactory;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+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;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+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;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+@Configuration
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@Conditional(KubernetesCloudAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(KubernetesCloudConfiguration.class)
+public class KubernetesCloudAutoConfiguration {
+ @Lazy
+ @Bean(name = "kubernetes-service-discovery")
+ @ConditionalOnClass(CamelContext.class)
+ public ServiceDiscovery configureServiceDiscoveryFactory(CamelContext camelContext, KubernetesCloudConfiguration configuration) throws Exception {
+ KubernetesServiceDiscoveryFactory factory = new KubernetesServiceDiscoveryFactory();
+
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null, false);
+ IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
+
+ return factory.newInstance(camelContext);
+ }
+
+ public static class Condition extends SpringBootCondition {
+ @Override
+ public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
+ boolean groupEnabled = isEnabled(conditionContext, "camel.cloud.", true);
+
+ ConditionMessage.Builder message = ConditionMessage.forCondition("camel.cloud.kubernetes");
+ if (isEnabled(conditionContext, "camel.cloud.kubernetes.", groupEnabled)) {
+ return ConditionOutcome.match(message.because("enabled"));
+ }
+
+ return ConditionOutcome.noMatch(message.because("not enabled"));
+ }
+
+ private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) {
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix);
+ return resolver.getProperty("enabled", Boolean.class, defaultValue);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java
new file mode 100644
index 0000000..5dd6902
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java
@@ -0,0 +1,54 @@
+/**
+ * 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.kubernetes.springboot.cloud;
+
+import org.apache.camel.component.kubernetes.KubernetesConfiguration;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud.kubernetes")
+public class KubernetesCloudConfiguration {
+ 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 KubernetesConfiguration {
+ private String lookup;
+
+ public String getLookup() {
+ return lookup;
+ }
+
+ public void setLookup(String lookup) {
+ this.lookup = lookup;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
index 5ef2258..310e1fe 100644
--- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,5 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.kubernetes.springboot.KubernetesComponentAutoConfiguration
+org.apache.camel.component.kubernetes.springboot.KubernetesComponentAutoConfiguration,\
+org.apache.camel.component.kubernetes.springboot.cloud.KubernetesCloudAutoConfiguration
[2/2] camel git commit: CAMEL-10686: service-call eip : generate
service-call auto configurations for spring-boot
Posted by lb...@apache.org.
CAMEL-10686: service-call eip : generate service-call auto configurations for spring-boot
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/61531455
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/61531455
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/61531455
Branch: refs/heads/master
Commit: 615314557f2a9db97266a23e6cec8d3ed5039d79
Parents: 2c3fa6c
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Feb 20 20:34:27 2017 +0100
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Feb 21 12:17:12 2017 +0100
----------------------------------------------------------------------
camel-core/src/main/docs/eips/filter-eip.adoc | 19 +--
.../impl/cloud/StaticServiceDiscovery.java | 16 ++-
.../model/cloud/ServiceCallDefinition.java | 15 +++
.../cloud/ConsulServiceDiscoveryFactory.java | 6 +-
.../dns/cloud/DnsServiceDiscoveryFactory.java | 4 +
.../etcd/cloud/EtcdServiceDiscoveryFactory.java | 6 +-
.../KubernetesServiceDiscoveryFactory.java | 6 +-
.../CamelCloudConfigurationProperties.java | 95 +++++++++++++++
.../spring/cloud/CamelCloudDiscoveryClient.java | 47 +++-----
.../spring/cloud/CamelCloudLoadBalancer.java | 22 +++-
...CamelCloudLoadBalancerAutoConfiguration.java | 62 ++++++++++
...melCloudServiceChooserAutoConfiguration.java | 44 +++++++
.../cloud/CamelCloudServiceDiscovery.java | 41 +++----
...lCloudServiceDiscoveryAutoConfiguration.java | 79 ++++++++++++
...amelCloudServiceFilterAutoConfiguration.java | 72 +++++++++++
.../ServiceCallConfigurationProperties.java | 119 -------------------
...erviceCallLoadBalancerAutoConfiguration.java | 54 ---------
...viceCallServiceChooserAutoConfiguration.java | 64 ----------
...ceCallServiceDiscoveryAutoConfiguration.java | 76 ------------
...rviceCallServiceFilterAutoConfiguration.java | 70 -----------
.../main/resources/META-INF/spring.factories | 6 +-
.../CamelCloudServiceCallConfiguration.java | 49 ++++++++
.../CamelCloudServiceCallConfigurationTest.java | 24 ++--
.../cloud/CamelCloudServiceCallRibbonTest.java | 34 +-----
.../spring/cloud/CamelCloudServiceCallTest.java | 41 +------
.../cloud/ConsulCloudAutoConfiguration.java | 79 ++++++++++++
.../cloud/ConsulCloudConfiguration.java | 45 +++++++
.../main/resources/META-INF/spring.factories | 3 +-
.../cloud/DnsCloudAutoConfiguration.java | 79 ++++++++++++
.../springboot/cloud/DnsCloudConfiguration.java | 45 +++++++
.../main/resources/META-INF/spring.factories | 3 +-
.../cloud/EtcdCloudAutoConfiguration.java | 83 +++++++++++++
.../cloud/EtcdCloudConfiguration.java | 54 +++++++++
.../main/resources/META-INF/spring.factories | 3 +-
.../cloud/KubernetesCloudAutoConfiguration.java | 79 ++++++++++++
.../cloud/KubernetesCloudConfiguration.java | 54 +++++++++
.../main/resources/META-INF/spring.factories | 3 +-
37 files changed, 1060 insertions(+), 541 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/camel-core/src/main/docs/eips/filter-eip.adoc
----------------------------------------------------------------------
diff --git a/camel-core/src/main/docs/eips/filter-eip.adoc b/camel-core/src/main/docs/eips/filter-eip.adoc
index ba5d7b8..fafc14c 100644
--- a/camel-core/src/main/docs/eips/filter-eip.adoc
+++ b/camel-core/src/main/docs/eips/filter-eip.adoc
@@ -1,6 +1,5 @@
-[[MessageFilter-MessageFilter]]
-Message Filter
-^^^^^^^^^^^^^^
+## Filter EIP
+### Message Filter
The http://www.enterpriseintegrationpatterns.com/Filter.html[Message
Filter] from the link:enterprise-integration-patterns.html[EIP patterns]
@@ -84,9 +83,7 @@ For further examples of this pattern in use you could look at the
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java?view=markup[junit
test case]
-[[MessageFilter-Usingstop]]
-*Using stop*
-++++++++++++
+#### *Using stop*
Stop is a bit different than a message filter as it will filter out all
messages and end the route entirely (filter only applies to its child
@@ -98,9 +95,7 @@ In the example below we do not want to route messages any further that
has the word `Bye` in the message body. Notice how we prevent this in
the when predicate by using the `.stop()`.
-[[MessageFilter-Knowingifwasfilteredornot]]
-Knowing if link:exchange.html[Exchange] was filtered or not
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+#### Knowing if link:exchange.html[Exchange] was filtered or not
*Available as of Camel 2.5*
@@ -118,13 +113,11 @@ with the value set based on the results of the last
link:message-filter.html[Message Filter] link:predicate.html[Predicate]
evaluated.
-[[MessageFilter-UsingThisPattern]]
-Using This Pattern
-++++++++++++++++++
+#### Using This Pattern
If you would like to use this EIP Pattern then please read the
link:getting-started.html[Getting Started], you may also find the
link:architecture.html[Architecture] useful particularly the description
of link:endpoint.html[Endpoint] and link:uris.html[URIs]. Then you could
try out some of the link:examples.html[Examples] first before trying
-this pattern out.
+this pattern out.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
index 1507b24..d017a11 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
@@ -26,6 +26,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
/**
@@ -52,6 +53,17 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
servers.forEach(this::addServer);
}
+ public void addServers(String serviceName, List<String> servers) {
+ for (String server : servers) {
+ String host = StringHelper.before(server, ":");
+ String port = StringHelper.after(server, ":");
+
+ if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
+ addServer(serviceName, host, Integer.valueOf(port));
+ }
+ }
+ }
+
/**
* Set the servers.
*
@@ -83,7 +95,9 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
String host = StringHelper.before(part, ":");
String port = StringHelper.after(part, ":");
- addServer(service, host, Integer.valueOf(port));
+ if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
+ addServer(service, host, Integer.valueOf(port));
+ }
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
index 5d8fe91..b6f7ab0 100644
--- a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
@@ -753,6 +753,10 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
if (answer == null && config != null) {
answer = retrieve(ServiceDiscovery.class, camelContext, config::getServiceDiscovery, config::getServiceDiscoveryRef);
}
+
+ if (answer == null) {
+ answer = camelContext.getRegistry().lookupByNameAndType("service-discovery", ServiceDiscovery.class);
+ }
if (answer == null) {
answer = findByType(camelContext, ServiceDiscovery.class);
}
@@ -804,6 +808,9 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
}
if (answer == null) {
+ answer = camelContext.getRegistry().lookupByNameAndType("service-filter", ServiceFilter.class);
+ }
+ if (answer == null) {
answer = findByType(camelContext, ServiceFilter.class);
}
@@ -833,6 +840,10 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
}
}
}
+
+ if (answer == null) {
+ answer = camelContext.getRegistry().lookupByNameAndType("service-chooser", ServiceChooser.class);
+ }
if (answer == null) {
answer = findByType(camelContext, ServiceChooser.class);
}
@@ -856,6 +867,10 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
if (answer == null && config != null) {
answer = retrieve(LoadBalancer.class, camelContext, config::getLoadBalancer, config::getLoadBalancerRef);
}
+
+ if (answer == null) {
+ answer = camelContext.getRegistry().lookupByNameAndType("load-balancer", LoadBalancer.class);
+ }
if (answer == null) {
answer = findByType(camelContext, LoadBalancer.class);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 9207d3e..04215ef 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
@@ -26,7 +26,11 @@ public class ConsulServiceDiscoveryFactory implements ServiceDiscoveryFactory {
private final ConsulConfiguration configuration;
public ConsulServiceDiscoveryFactory() {
- this.configuration = new ConsulConfiguration();
+ this(new ConsulConfiguration());
+ }
+
+ public ConsulServiceDiscoveryFactory(ConsulConfiguration configuration) {
+ this.configuration = configuration;
}
// *************************************************************************
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-dns/src/main/java/org/apache/camel/component/dns/cloud/DnsServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-dns/src/main/java/org/apache/camel/component/dns/cloud/DnsServiceDiscoveryFactory.java b/components/camel-dns/src/main/java/org/apache/camel/component/dns/cloud/DnsServiceDiscoveryFactory.java
index 18568d7..5c70532 100644
--- a/components/camel-dns/src/main/java/org/apache/camel/component/dns/cloud/DnsServiceDiscoveryFactory.java
+++ b/components/camel-dns/src/main/java/org/apache/camel/component/dns/cloud/DnsServiceDiscoveryFactory.java
@@ -28,6 +28,10 @@ public class DnsServiceDiscoveryFactory implements ServiceDiscoveryFactory {
this.configuration = new DnsConfiguration();
}
+ public DnsServiceDiscoveryFactory(DnsConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
// *************************************************************************
// Properties
// *************************************************************************
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/cloud/EtcdServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/cloud/EtcdServiceDiscoveryFactory.java b/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/cloud/EtcdServiceDiscoveryFactory.java
index 5bf89e0..3576843 100644
--- a/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/cloud/EtcdServiceDiscoveryFactory.java
+++ b/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/cloud/EtcdServiceDiscoveryFactory.java
@@ -28,7 +28,11 @@ public class EtcdServiceDiscoveryFactory implements ServiceDiscoveryFactory {
private String type;
public EtcdServiceDiscoveryFactory() {
- this.configuration = new EtcdConfiguration();
+ this(new EtcdConfiguration());
+ }
+
+ public EtcdServiceDiscoveryFactory(EtcdConfiguration configuration) {
+ this.configuration = configuration;
}
// *************************************************************************
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java
index 37bdff1..d93caa3 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/cloud/KubernetesServiceDiscoveryFactory.java
@@ -27,7 +27,11 @@ public class KubernetesServiceDiscoveryFactory implements ServiceDiscoveryFactor
private String lookup;
public KubernetesServiceDiscoveryFactory() {
- this.configuration = new KubernetesConfiguration();
+ this(new KubernetesConfiguration());
+ }
+
+ public KubernetesServiceDiscoveryFactory(KubernetesConfiguration configuration) {
+ this.configuration = configuration;
}
// *************************************************************************
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudConfigurationProperties.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudConfigurationProperties.java
index 00f91d8..97c1234 100644
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudConfigurationProperties.java
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudConfigurationProperties.java
@@ -16,11 +16,19 @@
*/
package org.apache.camel.spring.cloud;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "camel.cloud")
public class CamelCloudConfigurationProperties {
private boolean enabled = true;
+ private LoadBalancer loadBalancer = new LoadBalancer();
+ private ServiceDiscovery serviceDiscovery = new ServiceDiscovery();
+ private ServiceFilter serviceFilter = new ServiceFilter();
+ private ServiceChooser serviceChooser = new ServiceChooser();
public boolean isEnabled() {
return enabled;
@@ -29,4 +37,91 @@ public class CamelCloudConfigurationProperties {
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
+
+ public LoadBalancer getLoadBalancer() {
+ return loadBalancer;
+ }
+
+ public ServiceDiscovery getServiceDiscovery() {
+ return serviceDiscovery;
+ }
+
+ public ServiceFilter getServiceFilter() {
+ return serviceFilter;
+ }
+
+ public ServiceChooser getServiceChooser() {
+ return serviceChooser;
+ }
+
+ // *****************************************
+ // Nested configurations
+ // *****************************************
+
+ public static class LoadBalancer {
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ }
+
+ public static class ServiceDiscovery {
+ private boolean enabled = true;
+ private Map<String, List<String>> services = new HashMap<>();
+ private String cacheTimeout;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Map<String, List<String>> getServices() {
+ return services;
+ }
+
+ public String getCacheTimeout() {
+ return cacheTimeout;
+ }
+
+ public void setCacheTimeout(String cacheTimeout) {
+ this.cacheTimeout = cacheTimeout;
+ }
+ }
+
+ public static class ServiceFilter {
+ private boolean enabled = true;
+ private Map<String, List<String>> blacklist = new HashMap<>();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Map<String, List<String>> getBlacklist() {
+ return blacklist;
+ }
+ }
+
+ public static class ServiceChooser {
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java
index 194f518..5ffd6c1 100644
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudDiscoveryClient.java
@@ -17,30 +17,28 @@
package org.apache.camel.spring.cloud;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.camel.cloud.ServiceDiscovery;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
public class CamelCloudDiscoveryClient implements DiscoveryClient {
private final String description;
- private final Map<String, List<ServiceInstance>> services;
+ private final ServiceDiscovery serviceDiscovery;
private ServiceInstance localInstance;
- public CamelCloudDiscoveryClient(String description) {
- this(description, Collections.emptyMap());
+ public CamelCloudDiscoveryClient(String description, ServiceDiscovery serviceDiscovery) {
+ this(description, null, serviceDiscovery);
}
- public CamelCloudDiscoveryClient(String description, Map<String, List<ServiceInstance>> services) {
+ public CamelCloudDiscoveryClient(String description, ServiceInstance localServiceDiscovery,ServiceDiscovery serviceDiscovery) {
this.description = description;
- this.services = new LinkedHashMap<>(services);
- this.localInstance = null;
+ this.serviceDiscovery = serviceDiscovery;
+ this.localInstance = localServiceDiscovery;
}
@Override
@@ -53,31 +51,20 @@ public class CamelCloudDiscoveryClient implements DiscoveryClient {
return this.localInstance;
}
+ public CamelCloudDiscoveryClient setLocalServiceInstance(ServiceInstance instance) {
+ this.localInstance = instance;
+ return this;
+ }
+
@Override
public List<ServiceInstance> getInstances(String serviceId) {
- return services.get(serviceId);
+ return serviceDiscovery.getUpdatedListOfServices(serviceId).stream()
+ .map(s -> new DefaultServiceInstance(s.getName(), s.getHost(), s.getPort(), false, s.getMetadata()))
+ .collect(Collectors.toList());
}
@Override
public List<String> getServices() {
- return new ArrayList<>(services.keySet());
- }
-
- public CamelCloudDiscoveryClient addServiceInstance(ServiceInstance instance) {
- services.computeIfAbsent(instance.getServiceId(), key -> new LinkedList<>()).add(instance);
- return this;
- }
-
- public CamelCloudDiscoveryClient addServiceInstance(String serviceId, String host, int port) {
- return addServiceInstance(new DefaultServiceInstance(serviceId, host, port, false));
- }
-
- public CamelCloudDiscoveryClient setLocalServiceInstance(ServiceInstance instance) {
- this.localInstance = instance;
- return this;
- }
-
- public CamelCloudDiscoveryClient setLocalServiceInstance(String serviceId, String host, int port) {
- return setLocalServiceInstance(new DefaultServiceInstance(serviceId, host, port, false));
+ return Collections.emptyList();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java
index 08a73b8..c37a1eea 100644
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancer.java
@@ -21,11 +21,13 @@ import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.cloud.LoadBalancer;
import org.apache.camel.cloud.LoadBalancerFunction;
+import org.apache.camel.cloud.ServiceDefinition;
import org.apache.camel.impl.cloud.DefaultServiceDefinition;
import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
public class CamelCloudLoadBalancer extends ServiceSupport implements CamelContextAware, LoadBalancer {
@@ -53,8 +55,7 @@ public class CamelCloudLoadBalancer extends ServiceSupport implements CamelConte
ObjectHelper.notNull(camelContext, "camelContext");
ObjectHelper.notNull(loadBalancerClient, "loadBalancerClient");
- LOGGER.info("ServiceCall is using cloud load balancer of type: {}",
- loadBalancerClient.getClass());
+ LOGGER.info("ServiceCall is using cloud load balancer of type: {}", loadBalancerClient.getClass());
}
@Override
@@ -63,9 +64,22 @@ public class CamelCloudLoadBalancer extends ServiceSupport implements CamelConte
@Override
public <T> T process(String serviceName, LoadBalancerFunction<T> function) throws Exception {
+
+
return loadBalancerClient.execute(
- serviceName,
- i -> function.apply(new DefaultServiceDefinition(i.getServiceId(), i.getHost(), i.getPort(), i.getMetadata()))
+ serviceName, i -> function.apply(instanceToDefinition(i)));
+ }
+
+ // *******************************
+ // Helpers
+ // *******************************
+
+ private ServiceDefinition instanceToDefinition(ServiceInstance instance) {
+ return new DefaultServiceDefinition(
+ instance.getServiceId(),
+ instance.getHost(),
+ instance.getPort(),
+ instance.getMetadata()
);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancerAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancerAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancerAutoConfiguration.java
new file mode 100644
index 0000000..fb3e728
--- /dev/null
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudLoadBalancerAutoConfiguration.java
@@ -0,0 +1,62 @@
+/**
+ * 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.spring.cloud;
+
+
+import org.apache.camel.cloud.LoadBalancer;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration;
+import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.context.annotation.Scope;
+
+@Configuration
+@ConditionalOnBean({ CamelCloudAutoConfiguration.class, LoadBalancerClient.class })
+@AutoConfigureAfter({ LoadBalancerAutoConfiguration.class, CamelCloudServiceDiscoveryAutoConfiguration.class })
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudLoadBalancerAutoConfiguration.LoadBalancerCondition.class)
+public class CamelCloudLoadBalancerAutoConfiguration {
+ @Bean(name = "load-balancer")
+ public LoadBalancer cloudLoadBalancer(LoadBalancerClient loadBalancerClient) {
+ return new CamelCloudLoadBalancer(loadBalancerClient);
+ }
+
+ @Bean(name = "load-balancer-discovery-client")
+ public DiscoveryClient serviceDiscoveryClient(CamelCloudServiceDiscovery serviceDiscovery) {
+ return new CamelCloudDiscoveryClient("service-discovery-client", serviceDiscovery);
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class LoadBalancerCondition extends GroupCondition {
+ public LoadBalancerCondition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.load-balancer"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceChooserAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceChooserAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceChooserAutoConfiguration.java
new file mode 100644
index 0000000..81838ef
--- /dev/null
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceChooserAutoConfiguration.java
@@ -0,0 +1,44 @@
+/**
+ * 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.spring.cloud;
+
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnBean(CamelCloudAutoConfiguration.class)
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudServiceChooserAutoConfiguration.ServiceChooserCondition.class)
+public class CamelCloudServiceChooserAutoConfiguration {
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class ServiceChooserCondition extends GroupCondition {
+ public ServiceChooserCondition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.service-chooser"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java
index 3896494..8029894 100644
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscovery.java
@@ -17,36 +17,37 @@
package org.apache.camel.spring.cloud;
-import java.util.ArrayList;
import java.util.List;
-import java.util.stream.Collectors;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.cloud.ServiceDefinition;
-import org.apache.camel.impl.cloud.DefaultServiceDefinition;
-import org.apache.camel.impl.cloud.DefaultServiceDiscovery;
-import org.springframework.cloud.client.discovery.DiscoveryClient;
-
-public class CamelCloudServiceDiscovery extends DefaultServiceDiscovery {
- private final List<DiscoveryClient> clients;
-
- public CamelCloudServiceDiscovery(List<DiscoveryClient> clients) {
- this.clients = new ArrayList<>(clients);
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.impl.cloud.CachingServiceDiscovery;
+import org.apache.camel.impl.cloud.ChainedServiceDiscovery;
+
+public class CamelCloudServiceDiscovery implements ServiceDiscovery {
+ private ServiceDiscovery delegate;
+
+ public CamelCloudServiceDiscovery(Long timeout, List<ServiceDiscovery> serviceDiscoveryList) {
+ // Created a chained service discovery that collects services from multiple
+ // ServiceDiscovery
+ this.delegate = new ChainedServiceDiscovery(serviceDiscoveryList);
+
+ // If a timeout is provided, wrap the serviceDiscovery with a caching
+ // strategy so the discovery implementations are not queried for each
+ // discovery request
+ if (timeout != null && timeout > 0) {
+ this.delegate = CachingServiceDiscovery.wrap(this.delegate, timeout, TimeUnit.MILLISECONDS);
+ }
}
@Override
public List<ServiceDefinition> getInitialListOfServices(String name) {
- return getServers(name);
+ return delegate.getInitialListOfServices(name);
}
@Override
public List<ServiceDefinition> getUpdatedListOfServices(String name) {
- return getServers(name);
- }
-
- private List<ServiceDefinition> getServers(String name) {
- return clients.stream()
- .flatMap(c -> c.getInstances(name).stream())
- .map(s -> new DefaultServiceDefinition(s.getServiceId(), s.getHost(), s.getPort(), s.getMetadata()))
- .collect(Collectors.toList());
+ return delegate.getUpdatedListOfServices(name);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java
new file mode 100644
index 0000000..3581b5b
--- /dev/null
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceDiscoveryAutoConfiguration.java
@@ -0,0 +1,79 @@
+/**
+ * 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.spring.cloud;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.impl.cloud.StaticServiceDiscovery;
+import org.apache.camel.spring.boot.util.GroupCondition;
+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
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudServiceDiscoveryAutoConfiguration.ServiceDiscoveryCondition.class)
+public class CamelCloudServiceDiscoveryAutoConfiguration {
+
+ @Lazy
+ @Bean(name = "static-service-discovery")
+ public ServiceDiscovery staticServiceDiscovery(CamelCloudConfigurationProperties properties) {
+ StaticServiceDiscovery staticServiceDiscovery = new StaticServiceDiscovery();
+
+ Map<String, List<String>> services = properties.getServiceDiscovery().getServices();
+ for (Map.Entry<String, List<String>> entry : services.entrySet()) {
+ staticServiceDiscovery.addServers(entry.getKey(), entry.getValue());
+ }
+
+ return staticServiceDiscovery;
+ }
+
+ @Lazy
+ @Bean(name = "service-discovery")
+ public CamelCloudServiceDiscovery serviceDiscovery(
+ CamelContext camelContext, CamelCloudConfigurationProperties properties, List<ServiceDiscovery> serviceDiscoveryList) throws NoTypeConversionAvailableException{
+
+ String cacheTimeout = properties.getServiceDiscovery().getCacheTimeout();
+ Long timeout = null;
+
+ if (cacheTimeout != null) {
+ timeout = camelContext.getTypeConverter().mandatoryConvertTo(Long.class, timeout);
+ }
+
+ return new CamelCloudServiceDiscovery(timeout, serviceDiscoveryList);
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class ServiceDiscoveryCondition extends GroupCondition {
+ public ServiceDiscoveryCondition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.service-discovery"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceFilterAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceFilterAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceFilterAutoConfiguration.java
new file mode 100644
index 0000000..bb687bd
--- /dev/null
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelCloudServiceFilterAutoConfiguration.java
@@ -0,0 +1,72 @@
+/**
+ * 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.spring.cloud;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.impl.cloud.BlacklistServiceFilter;
+import org.apache.camel.impl.cloud.ChainedServiceFilter;
+import org.apache.camel.impl.cloud.HealthyServiceFilter;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
+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
+@EnableConfigurationProperties(CamelCloudConfigurationProperties.class)
+@Conditional(CamelCloudServiceFilterAutoConfiguration.ServiceFilterCondition.class)
+public class CamelCloudServiceFilterAutoConfiguration {
+ @Lazy
+ @Bean(name = "service-filter")
+ public ServiceFilter serviceFilter(CamelCloudConfigurationProperties properties) {
+ BlacklistServiceFilter blacklist = new BlacklistServiceFilter();
+
+ Map<String, List<String>> services = properties.getServiceFilter().getBlacklist();
+ for (Map.Entry<String, List<String>> entry : services.entrySet()) {
+ for (String part : entry.getValue()) {
+ String host = StringHelper.before(part, ":");
+ String port = StringHelper.after(part, ":");
+
+ if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
+ blacklist.addServer(entry.getKey(), host, Integer.parseInt(port));
+ }
+ }
+ }
+
+ return ChainedServiceFilter.wrap(new HealthyServiceFilter(), blacklist);
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class ServiceFilterCondition extends GroupCondition {
+ public ServiceFilterCondition() {
+ super(
+ "camel.cloud",
+ "camel.cloud.service-filter"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
deleted file mode 100644
index d316dcb..0000000
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
+++ /dev/null
@@ -1,119 +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.spring.cloud;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.cloud.servicecall")
-public class ServiceCallConfigurationProperties {
- private boolean enabled = true;
- private LoadBalancer loadBalancer = new LoadBalancer();
- private ServiceDiscovery serviceDiscovery = new ServiceDiscovery();
- private ServiceFilter serviceFilter = new ServiceFilter();
- private ServiceChooser serviceChooser = new ServiceChooser();
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public LoadBalancer getLoadBalancer() {
- return loadBalancer;
- }
-
- public ServiceDiscovery getServiceDiscovery() {
- return serviceDiscovery;
- }
-
- public ServiceFilter getServiceFilter() {
- return serviceFilter;
- }
-
- public ServiceChooser getServiceChooser() {
- return serviceChooser;
- }
-
- // *****************************************
- // Nested configurations
- // *****************************************
-
- public static class LoadBalancer {
- private boolean enabled = true;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
- }
-
- public static class ServiceDiscovery {
- private boolean enabled = true;
- private Map<String, List<String>> services = new HashMap<>();
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public Map<String, List<String>> getServices() {
- return services;
- }
- }
-
- public static class ServiceFilter {
- private boolean enabled = true;
- private Map<String, List<String>> blacklist = new HashMap<>();
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public Map<String, List<String>> getBlacklist() {
- return blacklist;
- }
- }
-
- public static class ServiceChooser {
- private boolean enabled = true;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java
deleted file mode 100644
index 32b66d2..0000000
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallLoadBalancerAutoConfiguration.java
+++ /dev/null
@@ -1,54 +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.spring.cloud;
-
-import org.apache.camel.cloud.LoadBalancer;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.context.annotation.Scope;
-
-@Configuration
-@ConditionalOnBean({ CamelCloudAutoConfiguration.class, LoadBalancerClient.class })
-@AutoConfigureAfter(LoadBalancerAutoConfiguration.class)
-@EnableConfigurationProperties(ServiceCallConfigurationProperties.class)
-public class ServiceCallLoadBalancerAutoConfiguration {
- @Lazy
- @Scope("prototype")
- @Bean(name = "cloud-load-balancer")
- @Conditional(ServiceCallLoadBalancerAutoConfiguration.LoadBalancerCondition.class)
- public LoadBalancer cloudLoadBalancer(LoadBalancerClient loadBalancerClient) {
- return new CamelCloudLoadBalancer(loadBalancerClient);
- }
-
- public static class LoadBalancerCondition extends GroupCondition {
- public LoadBalancerCondition() {
- super(
- "camel.cloud.servicecall",
- "camel.cloud.servicecall.load-balancer"
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java
deleted file mode 100644
index dae38a0..0000000
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceChooserAutoConfiguration.java
+++ /dev/null
@@ -1,64 +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.spring.cloud;
-
-import org.apache.camel.cloud.ServiceChooser;
-import org.apache.camel.impl.cloud.RandomServiceChooser;
-import org.apache.camel.impl.cloud.RoundRobinServiceChooser;
-import org.apache.camel.spring.boot.util.GroupCondition;
-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;
-import org.springframework.context.annotation.Scope;
-import org.springframework.core.annotation.Order;
-
-@Configuration
-@ConditionalOnBean(CamelCloudAutoConfiguration.class)
-@EnableConfigurationProperties(ServiceCallConfigurationProperties.class)
-public class ServiceCallServiceChooserAutoConfiguration {
-
- @Lazy
- @Scope("prototype")
- @Order(1)
- @Bean(name = "round-robin-service-chooser")
- @Conditional(ServiceCallServiceChooserAutoConfiguration.ServiceChooserCondition.class)
- public ServiceChooser roundRobinLoadBalancer() {
- return new RoundRobinServiceChooser();
- }
-
- @Lazy
- @Scope("prototype")
- @Order(2)
- @Bean(name = "random-service-chooser")
- @Conditional(ServiceCallServiceChooserAutoConfiguration.ServiceChooserCondition.class)
- public ServiceChooser randomLoadBalancer() {
- return new RandomServiceChooser();
- }
-
- public static class ServiceChooserCondition extends GroupCondition {
- public ServiceChooserCondition() {
- super(
- "camel.cloud.servicecall",
- "camel.cloud.servicecall.service-chooser"
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java
deleted file mode 100644
index 055aa28..0000000
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceDiscoveryAutoConfiguration.java
+++ /dev/null
@@ -1,76 +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.spring.cloud;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.StringHelper;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.cloud.client.discovery.DiscoveryClient;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.context.annotation.Scope;
-
-@Configuration
-@EnableConfigurationProperties(ServiceCallConfigurationProperties.class)
-public class ServiceCallServiceDiscoveryAutoConfiguration {
- @Lazy
- @Scope("prototype")
- @Bean(name = "service-discovery-client")
- @Conditional(ServiceCallServiceDiscoveryAutoConfiguration.ServiceDiscoveryCondition.class)
- public DiscoveryClient serviceDiscoveryClient(ServiceCallConfigurationProperties properties) {
- CamelCloudDiscoveryClient client = new CamelCloudDiscoveryClient("service-discovery-client");
-
- Map<String, List<String>> services = properties.getServiceDiscovery().getServices();
- for (Map.Entry<String, List<String>> entry : services.entrySet()) {
- for (String part : entry.getValue()) {
- String host = StringHelper.before(part, ":");
- String port = StringHelper.after(part, ":");
-
- if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
- client.addServiceInstance(entry.getKey(), host, Integer.parseInt(port));
- }
- }
- }
-
- return client;
- }
-
- @Lazy
- @Scope("prototype")
- @Bean(name = "service-discovery")
- @Conditional(ServiceCallServiceDiscoveryAutoConfiguration.ServiceDiscoveryCondition.class)
- public ServiceDiscovery serviceDiscovery(List<DiscoveryClient> clients) {
- return new CamelCloudServiceDiscovery(clients);
- }
-
- public static class ServiceDiscoveryCondition extends GroupCondition {
- public ServiceDiscoveryCondition() {
- super(
- "camel.cloud.servicecall",
- "camel.cloud.servicecall.service-discovery"
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
deleted file mode 100644
index 5f92678..0000000
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
+++ /dev/null
@@ -1,70 +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.spring.cloud;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.cloud.ServiceFilter;
-import org.apache.camel.impl.cloud.BlacklistServiceFilter;
-import org.apache.camel.impl.cloud.ChainedServiceFilter;
-import org.apache.camel.impl.cloud.HealthyServiceFilter;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.StringHelper;
-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;
-import org.springframework.context.annotation.Scope;
-
-@Configuration
-@EnableConfigurationProperties(ServiceCallConfigurationProperties.class)
-public class ServiceCallServiceFilterAutoConfiguration {
- @Lazy
- @Scope("prototype")
- @Bean(name = "service-filter-chained")
- @Conditional(ServiceCallServiceFilterAutoConfiguration.ServiceFilterCondition.class)
- public ServiceFilter chainedServiceFilter(ServiceCallConfigurationProperties properties) {
- BlacklistServiceFilter blacklist = new BlacklistServiceFilter();
-
- Map<String, List<String>> services = properties.getServiceFilter().getBlacklist();
- for (Map.Entry<String, List<String>> entry : services.entrySet()) {
- for (String part : entry.getValue()) {
- String host = StringHelper.before(part, ":");
- String port = StringHelper.after(part, ":");
-
- if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
- blacklist.addServer(entry.getKey(), host, Integer.parseInt(port));
- }
- }
- }
-
- return ChainedServiceFilter.wrap(new HealthyServiceFilter(), blacklist);
- }
-
- public static class ServiceFilterCondition extends GroupCondition {
- public ServiceFilterCondition() {
- super(
- "camel.cloud.servicecall",
- "camel.cloud.servicecall.service-filter"
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories b/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories
index d925094..d9c7e21 100644
--- a/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories
+++ b/components/camel-spring-cloud/src/main/resources/META-INF/spring.factories
@@ -17,6 +17,6 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.camel.spring.cloud.CamelCloudAutoConfiguration,\
-org.apache.camel.spring.cloud.ServiceCallServiceChooserAutoConfiguration,\
-org.apache.camel.spring.cloud.ServiceCallServiceDiscoveryAutoConfiguration,\
-org.apache.camel.spring.cloud.ServiceCallLoadBalancerAutoConfiguration
+org.apache.camel.spring.cloud.CamelCloudServiceChooserAutoConfiguration,\
+org.apache.camel.spring.cloud.CamelCloudServiceDiscoveryAutoConfiguration,\
+org.apache.camel.spring.cloud.CamelCloudLoadBalancerAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfiguration.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfiguration.java
new file mode 100644
index 0000000..e45e25c
--- /dev/null
+++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.spring.cloud;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class CamelCloudServiceCallConfiguration {
+ @Bean
+ public RouteBuilder myRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .serviceCall()
+ .name("custom-svc-list/hello");
+
+ from("jetty:http://localhost:9090/hello")
+ .transform()
+ .constant("9090");
+ from("jetty:http://localhost:9091/hello")
+ .transform()
+ .constant("9091");
+ from("jetty:http://localhost:9092/hello")
+ .transform()
+ .constant("9092");
+ }
+ };
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java
index cb992a4..a5d9a79 100644
--- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java
+++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallConfigurationTest.java
@@ -42,14 +42,14 @@ import static org.junit.Assert.assertTrue;
classes = {
CamelAutoConfiguration.class,
CamelCloudAutoConfiguration.class,
- ServiceCallServiceChooserAutoConfiguration.class
+ CamelCloudServiceChooserAutoConfiguration.class
},
properties = {
- "camel.cloud.servicecall.enabled=false",
- "camel.cloud.servicecall.service-discovery.enabled=false",
- "camel.cloud.servicecall.service-filter.enabled=false",
- "camel.cloud.servicecall.service-chooser.enabled=true",
- "camel.cloud.servicecall.load-balancer.enabled=false",
+ "camel.cloud.enabled=false",
+ "camel.cloud.service-discovery.enabled=false",
+ "camel.cloud.service-filter.enabled=false",
+ "camel.cloud.service-chooser.enabled=true",
+ "camel.cloud.load-balancer.enabled=false",
"debug=false"
}
)
@@ -61,15 +61,15 @@ public class CamelCloudServiceCallConfigurationTest {
public void doTest() throws Exception {
Environment env = ctx.getEnvironment();
- assertFalse(env.getProperty("camel.cloud.servicecall.enabled", Boolean.class));
- assertFalse(env.getProperty("camel.cloud.servicecall.service-discovery.enabled", Boolean.class));
- assertFalse(env.getProperty("camel.cloud.servicecall.service-filter.enabled", Boolean.class));
- assertTrue(env.getProperty("camel.cloud.servicecall.service-chooser.enabled", Boolean.class));
- assertFalse(env.getProperty("camel.cloud.servicecall.load-balancer.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.service-discovery.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.service-filter.enabled", Boolean.class));
+ assertTrue(env.getProperty("camel.cloud.service-chooser.enabled", Boolean.class));
+ assertFalse(env.getProperty("camel.cloud.load-balancer.enabled", Boolean.class));
assertTrue(ctx.getBeansOfType(ServiceDiscovery.class).isEmpty());
assertTrue(ctx.getBeansOfType(ServiceFilter.class).isEmpty());
- assertFalse(ctx.getBeansOfType(ServiceChooser.class).isEmpty());
+ assertTrue(ctx.getBeansOfType(ServiceChooser.class).isEmpty());
assertTrue(ctx.getBeansOfType(LoadBalancer.class).isEmpty());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java
index b038a19..c80489e 100644
--- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java
+++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallRibbonTest.java
@@ -18,7 +18,6 @@
package org.apache.camel.spring.cloud;
import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
import org.junit.Assert;
import org.junit.Test;
@@ -26,8 +25,6 @@ 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.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@@ -38,11 +35,11 @@ import org.springframework.test.context.junit4.SpringRunner;
classes = {
CamelAutoConfiguration.class,
CamelCloudAutoConfiguration.class,
- CamelCloudServiceCallRibbonTest.TestConfiguration.class
+ CamelCloudServiceCallConfiguration.class
},
properties = {
"ribbon.eureka.enabled=false",
- "ribbon.listOfServers=localhost:9090,localhost:9091",
+ "ribbon.listOfServers=localhost:9090,localhost:9092",
"ribbon.ServerListRefreshInterval=15000",
"debug=false"
}
@@ -54,32 +51,7 @@ public class CamelCloudServiceCallRibbonTest {
@Test
public void testServiceCall() throws Exception {
Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class));
- Assert.assertEquals("9091", template.requestBody("direct:start", null, String.class));
+ Assert.assertEquals("9092", template.requestBody("direct:start", null, String.class));
}
-
- // **************************
- // Configuration
- // **************************
-
- @Configuration
- public static class TestConfiguration {
- @Bean
- public RouteBuilder myRouteBuilder() {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .serviceCall()
- .name("service-call");
-
- from("jetty:http://localhost:9090")
- .transform().constant("9090");
- from("jetty:http://localhost:9091")
- .transform().constant("9091");
- }
- };
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
index c22b029..333561c 100644
--- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
+++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
@@ -18,7 +18,6 @@
package org.apache.camel.spring.cloud;
import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
import org.junit.Assert;
import org.junit.Test;
@@ -26,8 +25,6 @@ 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.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@@ -38,12 +35,12 @@ import org.springframework.test.context.junit4.SpringRunner;
classes = {
CamelAutoConfiguration.class,
CamelCloudAutoConfiguration.class,
- CamelCloudServiceCallTest.TestConfiguration.class
+ CamelCloudServiceCallConfiguration.class
},
properties = {
- "camel.cloud.servicecall.load-balancer.enabled=false",
- "camel.cloud.servicecall.service-discovery.services[custom-svc-list]=localhost:9090,localhost:9091,localhost:9092",
- "camel.cloud.servicecall.service-filter.blacklist[custom-svc-list]=localhost:9091",
+ "camel.cloud.load-balancer.enabled=false",
+ "camel.cloud.service-discovery.services[custom-svc-list]=localhost:9090,localhost:9091,localhost:9092",
+ "camel.cloud.service-filter.blacklist[custom-svc-list]=localhost:9091",
"ribbon.enabled=false",
"debug=false"
}
@@ -57,35 +54,5 @@ public class CamelCloudServiceCallTest {
Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class));
Assert.assertEquals("9092", template.requestBody("direct:start", null, String.class));
}
-
- // **************************
- // Configuration
- // **************************
-
- @Configuration
- public static class TestConfiguration {
- @Bean
- public RouteBuilder myRouteBuilder() {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .serviceCall()
- .name("custom-svc-list/hello");
-
- from("jetty:http://localhost:9090/hello")
- .transform()
- .constant("9090");
- from("jetty:http://localhost:9091/hello")
- .transform()
- .constant("9091");
- from("jetty:http://localhost:9092/hello")
- .transform()
- .constant("9092");
- }
- };
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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
new file mode 100644
index 0000000..db5cf32
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
@@ -0,0 +1,79 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.component.consul.cloud.ConsulServiceDiscoveryFactory;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+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;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+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;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+@Configuration
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@Conditional(ConsulCloudAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(ConsulCloudConfiguration.class)
+public class ConsulCloudAutoConfiguration {
+ @Lazy
+ @Bean(name = "consul-service-discovery")
+ @ConditionalOnClass(CamelContext.class)
+ public ServiceDiscovery configureServiceDiscoveryFactory(CamelContext camelContext, ConsulCloudConfiguration configuration) throws Exception {
+ ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
+
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null, false);
+ IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
+
+ return factory.newInstance(camelContext);
+ }
+
+ public static class Condition extends SpringBootCondition {
+ @Override
+ public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
+ boolean groupEnabled = isEnabled(conditionContext, "camel.cloud.", true);
+
+ ConditionMessage.Builder message = ConditionMessage.forCondition("camel.cloud.consul");
+ if (isEnabled(conditionContext, "camel.cloud.consul.", groupEnabled)) {
+ return ConditionOutcome.match(message.because("enabled"));
+ }
+
+ return ConditionOutcome.noMatch(message.because("not enabled"));
+ }
+
+ private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) {
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix);
+ return resolver.getProperty("enabled", Boolean.class, defaultValue);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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
new file mode 100644
index 0000000..2339859
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
@@ -0,0 +1,45 @@
+/**
+ * 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 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 {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 85286f6..4517ac3 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
@@ -16,4 +16,5 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.consul.springboot.ConsulComponentAutoConfiguration
+org.apache.camel.component.consul.springboot.ConsulComponentAutoConfiguration,\
+org.apache.camel.component.consul.springboot.cloud.ConsulCloudAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
new file mode 100644
index 0000000..a3e9b09
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
@@ -0,0 +1,79 @@
+/**
+ * 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.dns.springboot.cloud;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.component.dns.cloud.DnsServiceDiscoveryFactory;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+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;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+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;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+@Configuration
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@Conditional(DnsCloudAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(DnsCloudConfiguration.class)
+public class DnsCloudAutoConfiguration {
+ @Lazy
+ @Bean(name = "dns-service-discovery")
+ @ConditionalOnClass(CamelContext.class)
+ public ServiceDiscovery configureServiceDiscoveryFactory(CamelContext camelContext, DnsCloudConfiguration configuration) throws Exception {
+ DnsServiceDiscoveryFactory factory = new DnsServiceDiscoveryFactory();
+
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null, false);
+ IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
+
+ return factory.newInstance(camelContext);
+ }
+
+ public static class Condition extends SpringBootCondition {
+ @Override
+ public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
+ boolean groupEnabled = isEnabled(conditionContext, "camel.cloud.", true);
+
+ ConditionMessage.Builder message = ConditionMessage.forCondition("camel.cloud.dns");
+ if (isEnabled(conditionContext, "camel.cloud.dns.", groupEnabled)) {
+ return ConditionOutcome.match(message.because("enabled"));
+ }
+
+ return ConditionOutcome.noMatch(message.because("not enabled"));
+ }
+
+ private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) {
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix);
+ return resolver.getProperty("enabled", Boolean.class, defaultValue);
+ }
+ }
+}