This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 01b04f54cca361fec0d7fcf2c736e6ddb75e1fc6 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Wed May 23 16:35:40 2018 +0200 CAMEL-12531: camel cloud : create a spring cloud based camel-service example --- .../cloud/CamelCloudConfigurationProperties.java | 13 ++ ...dServiceCallConfigurationAutoConfiguration.java | 24 ++-- .../cloud/CamelSpringCloudServiceDiscovery.java | 49 +++++++ ...ringCloudServiceDiscoveryAutoConfiguration.java | 61 +++++++++ .../src/main/resources/META-INF/spring.factories | 1 + examples/README.adoc | 2 + .../README.adoc | 67 ++++++++++ .../consumer/pom.xml | 141 +++++++++++++++++++++ .../apache/camel/example/ConsumerApplication.java | 57 +++++++++ .../src/main/resources/application.properties | 51 ++++++++ .../pom.xml | 58 +++++++++ .../service/pom.xml | 132 +++++++++++++++++++ .../apache/camel/example/ServiceApplication.java | 50 ++++++++ .../src/main/resources/application.properties | 33 +++++ examples/pom.xml | 1 + 15 files changed, 731 insertions(+), 9 deletions(-) diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java index 7fbd65d..bfbd8b2 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudConfigurationProperties.java @@ -99,6 +99,11 @@ public class CamelCloudConfigurationProperties { private String loadBalancer; /** + * Determine if the default load balancer should be used instead of any auto discovered one. + */ + private boolean defaultLoadBalancer; + + /** * The {@link Expression} to use. */ private String expression; @@ -156,6 +161,14 @@ public class CamelCloudConfigurationProperties { this.loadBalancer = loadBalancer; } + public boolean isDefaultLoadBalancer() { + return defaultLoadBalancer; + } + + public void setDefaultLoadBalancer(boolean defaultLoadBalancer) { + this.defaultLoadBalancer = defaultLoadBalancer; + } + public String getExpression() { return expression; } diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java index 4da2718..0c8f93b 100644 --- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java +++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationAutoConfiguration.java @@ -45,16 +45,22 @@ public class CamelCloudServiceCallConfigurationAutoConfiguration { @Bean(name = ServiceCallDefinitionConstants.DEFAULT_SERVICE_CALL_CONFIG_ID) @ConditionalOnMissingBean(name = ServiceCallDefinitionConstants.DEFAULT_SERVICE_CALL_CONFIG_ID) public ServiceCallConfigurationDefinition serviceCallConfiguration() throws Exception { - ServiceCallConfigurationDefinition definition = new ServiceCallConfigurationDefinition(); - ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getComponent(), definition::setComponent); - ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getUri(), definition::setUri); - ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getServiceDiscovery(), definition::setServiceDiscoveryRef); - ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getServiceFilter(), definition::setServiceFilterRef); - ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getServiceChooser(), definition::setServiceChooserRef); - ObjectHelper.ifNotEmpty(configurationProperties.getServiceCall().getLoadBalancer(), definition::setLoadBalancerRef); + final ServiceCallConfigurationDefinition definition = new ServiceCallConfigurationDefinition(); + final CamelCloudConfigurationProperties.ServiceCall serviceCall = configurationProperties.getServiceCall(); - String expression = configurationProperties.getServiceCall().getExpression(); - String expressionLanguage = configurationProperties.getServiceCall().getExpressionLanguage(); + ObjectHelper.ifNotEmpty(serviceCall.getComponent(), definition::setComponent); + ObjectHelper.ifNotEmpty(serviceCall.getUri(), definition::setUri); + ObjectHelper.ifNotEmpty(serviceCall.getServiceDiscovery(), definition::setServiceDiscoveryRef); + ObjectHelper.ifNotEmpty(serviceCall.getServiceFilter(), definition::setServiceFilterRef); + ObjectHelper.ifNotEmpty(serviceCall.getServiceChooser(), definition::setServiceChooserRef); + ObjectHelper.ifNotEmpty(serviceCall.getLoadBalancer(), definition::setLoadBalancerRef); + + if (serviceCall.getLoadBalancer() == null && serviceCall.isDefaultLoadBalancer()) { + definition.defaultLoadBalancer(); + } + + final String expression = serviceCall.getExpression(); + final String expressionLanguage = serviceCall.getExpressionLanguage(); if (ObjectHelper.isNotEmpty(expression) && ObjectHelper.isNotEmpty(expressionLanguage)) { Language language = camelContext.resolveLanguage(expressionLanguage); diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelSpringCloudServiceDiscovery.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelSpringCloudServiceDiscovery.java new file mode 100644 index 0000000..211f551 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelSpringCloudServiceDiscovery.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 java.util.List; +import java.util.stream.Collectors; + +import org.apache.camel.cloud.ServiceDefinition; +import org.apache.camel.cloud.ServiceDiscovery; +import org.apache.camel.impl.cloud.DefaultServiceDefinition; +import org.springframework.cloud.client.discovery.DiscoveryClient; + +public class CamelSpringCloudServiceDiscovery implements ServiceDiscovery { + private final DiscoveryClient discoveryClient; + + public CamelSpringCloudServiceDiscovery(DiscoveryClient discoveryClient) { + this.discoveryClient = discoveryClient; + } + + @Override + public List<ServiceDefinition> getServices(String name) { + return discoveryClient.getInstances(name).stream() + .map( + si -> { + return DefaultServiceDefinition.builder() + .withName(si.getServiceId()) + .withHost(si.getHost()) + .withPort(si.getPort()) + .withId(name) + .withMeta(si.getMetadata()) + .build(); + } + ).collect(Collectors.toList()); + } +} diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelSpringCloudServiceDiscoveryAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelSpringCloudServiceDiscoveryAutoConfiguration.java new file mode 100644 index 0000000..014b9f7 --- /dev/null +++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/CamelSpringCloudServiceDiscoveryAutoConfiguration.java @@ -0,0 +1,61 @@ +/** + * 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.ServiceDiscovery; +import org.apache.camel.spring.boot.cloud.CamelCloudAutoConfiguration; +import org.apache.camel.spring.boot.cloud.CamelCloudConfigurationProperties; +import org.apache.camel.spring.boot.cloud.CamelCloudServiceDiscoveryAutoConfiguration; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConditionalOnBean({ CamelCloudAutoConfiguration.class, DiscoveryClient.class }) +@AutoConfigureAfter(CompositeDiscoveryClientAutoConfiguration.class) +@AutoConfigureBefore(CamelCloudServiceDiscoveryAutoConfiguration.class) +@EnableConfigurationProperties(CamelCloudConfigurationProperties.class) +@Conditional(CamelSpringCloudServiceDiscoveryAutoConfiguration.ServiceDiscoveryCondition.class) +public class CamelSpringCloudServiceDiscoveryAutoConfiguration { + + @Bean(name = "spring-cloud-service-discovery") + @ConditionalOnMissingBean + public ServiceDiscovery springCloudServiceDiscovery(DiscoveryClient discoveryClient) { + return new CamelSpringCloudServiceDiscovery(discoveryClient); + } + + // ******************************* + // Condition + // ******************************* + + public static class ServiceDiscoveryCondition extends GroupCondition { + public ServiceDiscoveryCondition() { + super( + "camel.cloud", + "camel.cloud.service-discovery" + ); + } + } +} 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 ae6d075..654c17d 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,5 +17,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.apache.camel.spring.cloud.CamelSpringCloudDiscoveryClientAutoConfiguration,\ + org.apache.camel.spring.cloud.CamelSpringCloudServiceDiscoveryAutoConfiguration,\ org.apache.camel.spring.cloud.CamelSpringCloudServiceLoadBalancerAutoConfiguration,\ org.apache.camel.spring.cloud.CamelSpringCloudServiceRegistryAutoConfiguration diff --git a/examples/README.adoc b/examples/README.adoc index e19ce95..5e45c4c 100644 --- a/examples/README.adoc +++ b/examples/README.adoc @@ -78,6 +78,8 @@ Number of Examples: 102 (8 deprecated) | link:camel-example-spring-cloud-servicecall/README.adoc[Spring Cloud Servicecall] (camel-example-spring-cloud-servicecall) | Cloud | An example showing how to work with Camel ServiceCall EIP and Spring Cloud +| link:camel-example-spring-cloud-serviceregistry/README.adoc[Spring Cloud Service registry] (camel-example-spring-cloud-serviceregistry) | Cloud | An example showing how to work with Camel Service Registry and Spring Cloud + | link:camel-example-spring-boot-clustered-route-controller/readme.adoc[Spring Boot Clustered Route Controller] (camel-example-spring-boot-clustered-route-controller) | Clustering | An example showing how to work with Camel's Clustered Route Controller and Spring Boot | link:camel-example-spring-boot-master/readme.adoc[Spring Boot Master] (camel-example-spring-boot-master) | Clustering | An example showing how to work with Camel's Master component and Spring Boot diff --git a/examples/camel-example-spring-cloud-serviceregistry/README.adoc b/examples/camel-example-spring-cloud-serviceregistry/README.adoc new file mode 100644 index 0000000..28e37d2 --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/README.adoc @@ -0,0 +1,67 @@ +# Spring Cloud and ServiceCall EIP Example + +This example show how to use Camel with Service Registry, spring-cloud and consul. + +This example includes two maven modules: + + - service that exposes a number of services + - consumer that consumes services + +## Configuration + +The consumer is configured in the src/main/resources/application.properties + +## Build + +You can build this example using + + mvn compile + +## Run the example + +Using multiple shells: + + - start consul: + + docker run --rm -ti --publish 8500:8500 \ + consul:1.0.0 \ + agent \ + -dev \ + -server \ + -ui \ + -bootstrap \ + -datacenter camel \ + -client 0.0.0.0 \ + -log-level trace + + - start the service: + + $ cd service + $ mvn spring-boot:run + + - start the consumer + + $ cd consumer + $ mvn spring-boot:run + +## Test the example: + +In a new shell: + + $ curl localhost:8080/camel/serviceCall + Hi!, I'm service-1 on path: /path/to/service/1 + $ curl localhost:8080/camel/serviceCall + Hi!, I'm service-1 on path: /path/to/service/2 + +## Web console + +You can open the Consul web console + + http://localhost:8500/ui + +Where you can find information about the services and its state. + +## More information + +You can find more information about Apache Camel at the website: http://camel.apache.org/ + diff --git a/examples/camel-example-spring-cloud-serviceregistry/consumer/pom.xml b/examples/camel-example-spring-cloud-serviceregistry/consumer/pom.xml new file mode 100644 index 0000000..c0c293c --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/consumer/pom.xml @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>camel-example-spring-cloud-serviceregistry</artifactId> + <version>2.22.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-spring-cloud-serviceregistry-consumer</artifactId> + <name>Camel :: Example :: Spring Cloud :: Service Registry :: Consumer</name> + <description>An example showing how to work with Camel Service Registry and Spring Cloud (Consumer)</description> + + <properties> + <category>Cloud</category> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <spring.boot-version>${spring-boot-version}</spring.boot-version> + <spring.cloud-version>2.0.0.RC1</spring.cloud-version> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Spring Boot BOM --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>${spring.boot-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-consul-dependencies</artifactId> + <version>${spring.cloud-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-dependencies</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <!-- Spring Boot --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-consul-discovery</artifactId> + </dependency> + + <!-- Camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-cloud-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-cloud-consul-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-undertow-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-servlet-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jackson-starter</artifactId> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring-boot-version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> + +</project> diff --git a/examples/camel-example-spring-cloud-serviceregistry/consumer/src/main/java/org/apache/camel/example/ConsumerApplication.java b/examples/camel-example-spring-cloud-serviceregistry/consumer/src/main/java/org/apache/camel/example/ConsumerApplication.java new file mode 100644 index 0000000..9134f3a --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/consumer/src/main/java/org/apache/camel/example/ConsumerApplication.java @@ -0,0 +1,57 @@ +/** + * 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.example; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.stereotype.Component; + +//CHECKSTYLE:OFF +/** + * A sample Spring Boot application that starts the Camel routes. + */ +@SpringBootApplication +@EnableDiscoveryClient +public class ConsumerApplication { + @Component + public class ConsumerRoute extends RouteBuilder { + @Override + public void configure() throws Exception { + rest("/serviceCall") + .verb("GET") + .to("direct:service-call"); + + from("direct:service-call") + .setBody().constant(null) + .removeHeaders("CamelHttp*") + .serviceCall("my-service") + .convertBodyTo(String.class) + .log("answer: ${body}"); + } + } + + /** + * A main method to start this application. + */ + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } + +} +//CHECKSTYLE:ON diff --git a/examples/camel-example-spring-cloud-serviceregistry/consumer/src/main/resources/application.properties b/examples/camel-example-spring-cloud-serviceregistry/consumer/src/main/resources/application.properties new file mode 100644 index 0000000..6f6ca73 --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/consumer/src/main/resources/application.properties @@ -0,0 +1,51 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + + +# Spring Boot +management.endpoints.enabled-by-default=false +management.endpoint.health.enabled=true + +spring.application.name = ${random.uuid} + +# Spring cloud +spring.cloud.consul.enabled = true +spring.cloud.consul.config.enabled = false +spring.cloud.consul.discovery.enabled = true +spring.cloud.service-registry.auto-registration.enabled = false +ribbon.enabled = false + +# Camel +camel.springboot.main-run-controller=true +camel.springboot.jmx-enabled=false + +camel.rest.component = servlet +camel.rest.binding-mode = auto + + + +camel.cloud.service-call.component = undertow + +# this should not be needed but there is a bug or misbehavior +# on spring cloud netflix side that prevent ribbon load +# balancer to propagate metadata from i.e. consul, see: +# +# https://github.com/spring-cloud/spring-cloud-consul/issues/424 +# +camel.cloud.ribbon.load-balancer.enabled = false +camel.cloud.service-call.default-load-balancer = true +camel.cloud.service-call.service-chooser = roundrobin diff --git a/examples/camel-example-spring-cloud-serviceregistry/pom.xml b/examples/camel-example-spring-cloud-serviceregistry/pom.xml new file mode 100644 index 0000000..c207de1 --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>examples</artifactId> + <version>2.22.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-spring-cloud-serviceregistry</artifactId> + <name>Camel :: Example :: Spring Cloud :: ServiceRegistry</name> + <description>An example showing how to work with Camel Service registry and Spring Cloud</description> + <packaging>pom</packaging> + + <properties> + <category>Cloud</category> + </properties> + + <!-- spring-cloud with support for spring boot 2 is not in maven central yet --> + <repositories> + <repository> + <id>spring-milestones</id> + <name>Spring Milestones</name> + <url>https://repo.spring.io/libs-milestone</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + + <modules> + <module>consumer</module> + <module>service</module> + </modules> + +</project> diff --git a/examples/camel-example-spring-cloud-serviceregistry/service/pom.xml b/examples/camel-example-spring-cloud-serviceregistry/service/pom.xml new file mode 100644 index 0000000..eb57bb0 --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/service/pom.xml @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>camel-example-spring-cloud-serviceregistry</artifactId> + <version>2.22.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-spring-cloud-serviceregistry-service</artifactId> + <name>Camel :: Example :: Spring Cloud :: Service Registry :: Service</name> + <description>An example showing how to work with Camel Service Registry and Spring Cloud (Service)</description> + + <properties> + <category>Cloud</category> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <spring.boot-version>${spring-boot-version}</spring.boot-version> + <spring.cloud-version>2.0.0.RC1</spring.cloud-version> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Spring Boot BOM --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>${spring.boot-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-consul-dependencies</artifactId> + <version>${spring.cloud-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-dependencies</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <!-- Spring Boot --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-consul-discovery</artifactId> + </dependency> + + <!-- Camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-undertow-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-cloud-consul-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-service-starter</artifactId> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring-boot-version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/examples/camel-example-spring-cloud-serviceregistry/service/src/main/java/org/apache/camel/example/ServiceApplication.java b/examples/camel-example-spring-cloud-serviceregistry/service/src/main/java/org/apache/camel/example/ServiceApplication.java new file mode 100644 index 0000000..31ff9c8 --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/service/src/main/java/org/apache/camel/example/ServiceApplication.java @@ -0,0 +1,50 @@ +/** + * 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.example; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Component; +import org.springframework.util.SocketUtils; + +//CHECKSTYLE:OFF +/** + * A sample Spring Boot application that starts the Camel routes. + */ +@SpringBootApplication +public class ServiceApplication { + + @Component + public class Services extends RouteBuilder { + public void configure() throws Exception { + fromF("service:my-service:undertow:http://localhost:%d/path/to/service/1", SocketUtils.findAvailableTcpPort()) + .transform().simple("Hi!, I'm service-1 on path: /path/to/service/1"); + fromF("service:my-service:undertow:http://localhost:%d/path/to/service/2", SocketUtils.findAvailableTcpPort()) + .transform().simple("Hi!, I'm service-1 on path: /path/to/service/2"); + } + } + + /** + * A main method to start this application. + */ + public static void main(String[] args) { + SpringApplication.run(ServiceApplication.class, args); + } + +} +//CHECKSTYLE:ON diff --git a/examples/camel-example-spring-cloud-serviceregistry/service/src/main/resources/application.properties b/examples/camel-example-spring-cloud-serviceregistry/service/src/main/resources/application.properties new file mode 100644 index 0000000..b0e9629 --- /dev/null +++ b/examples/camel-example-spring-cloud-serviceregistry/service/src/main/resources/application.properties @@ -0,0 +1,33 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# Spring Boot +management.endpoints.enabled-by-default = false +management.endpoint.health.enabled = true + +spring.application.name = ${random.uuid} + +# Spring cloud +spring.cloud.consul.enabled = true +spring.cloud.consul.config.enabled = false +spring.cloud.consul.discovery.enabled = true +spring.cloud.service-registry.auto-registration.enabled = false + +# Camel +camel.springboot.main-run-controller = true +camel.springboot.jmx-enabled = false + diff --git a/examples/pom.xml b/examples/pom.xml index cc9b066..9c3eceb 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -116,6 +116,7 @@ <module>camel-example-spring-boot-supervising-route-controller</module> <module>camel-example-spring-boot-xml</module> <module>camel-example-spring-cloud-servicecall</module> + <module>camel-example-spring-cloud-serviceregistry</module> <module>camel-example-spring-javaconfig</module> <module>camel-example-spring-jms</module> <module>camel-example-spring-ws</module> -- To stop receiving notification emails like this one, please contact lburgazz...@apache.org.