This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit dca815f222f7d13627ae0d95d77a222dd0a71c95 Author: akoufoudakis <[email protected]> AuthorDate: Thu May 14 18:27:52 2020 +0200 Widget-Gadget example with SpringBoot --- .../pom.xml | 139 +++++++++++++++++++++ .../src/main/data/order1.json | 7 ++ .../src/main/data/order2.json | 7 ++ .../src/main/java/sample/camel/AmqpConfig.java | 67 ++++++++++ .../src/main/java/sample/camel/OrderRoute.java | 36 ++++++ .../main/java/sample/camel/WidgetGadgetApp.java | 11 ++ .../main/java/sample/camel/WidgetGadgetRoute.java | 26 ++++ .../src/main/resources/application.properties | 4 + 8 files changed, 297 insertions(+) diff --git a/examples/camel-example-spring-boot-widget-gadget/pom.xml b/examples/camel-example-spring-boot-widget-gadget/pom.xml new file mode 100644 index 0000000..397f575 --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/pom.xml @@ -0,0 +1,139 @@ +<?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/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>examples</artifactId> + <groupId>org.apache.camel.springboot.example</groupId> + <version>3.3.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-example-spring-boot-widget-gadget</artifactId> + <name>Camel SB Examples :: </name> + <description>The widget and gadget example from EIP book, running on Spring Boot</description> + + <properties> + <category>Messaging</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> + </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> + + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel.springboot</groupId> + <artifactId>camel-spring-boot-dependencies</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + + </dependencyManagement> + + <dependencies> + + <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.apache.camel.springboot</groupId> + <artifactId>camel-amqp-starter</artifactId> + </dependency> + + <!-- Camel --> + <dependency> + <groupId>org.apache.camel.springboot</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-amqp</artifactId> + <version>${camel-version}</version> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jsonpath</artifactId> + <version>${camel-version}</version> + </dependency> + + + <!-- test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <version>${camel-version}</version> + <scope>test</scope> + </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> \ No newline at end of file diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/data/order1.json b/examples/camel-example-spring-boot-widget-gadget/src/main/data/order1.json new file mode 100644 index 0000000..37579f8 --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/data/order1.json @@ -0,0 +1,7 @@ +{ "__comment__": "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 [...] + "order" : { + "customerId": "123", + "product": "widget", + "amount": "2" + } +} \ No newline at end of file diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/data/order2.json b/examples/camel-example-spring-boot-widget-gadget/src/main/data/order2.json new file mode 100644 index 0000000..6d442de --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/data/order2.json @@ -0,0 +1,7 @@ +{ "__comment__": "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 [...] + "order" : { + "customerId": "456", + "product": "gadget", + "amount": "3" + } +} \ No newline at end of file diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/AmqpConfig.java b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/AmqpConfig.java new file mode 100644 index 0000000..326277c --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/AmqpConfig.java @@ -0,0 +1,67 @@ +/* + * 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 sample.camel; + +import org.apache.qpid.jms.JmsConnectionFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AmqpConfig { + + @Value("${AMQP_SERVICE_USERNAME}") + private String userName; + @Value("${AMQP_SERVICE_PASSWORD}") + private String pass; + @Value("${AMQP_REMOTE_URI}") + private String remoteUri; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPass() { + return pass; + } + + public void setPass(String pass) { + this.pass = pass; + } + + public String getRemoteUri() { + return remoteUri; + } + + public void setRemoteUri(String remoteUri) { + this.remoteUri = remoteUri; + } + + @Bean + public JmsConnectionFactory amqpConnectionFactory() { + JmsConnectionFactory jmsConnectionFactory = new JmsConnectionFactory(); + jmsConnectionFactory.setRemoteURI(remoteUri); + jmsConnectionFactory.setUsername(userName); + jmsConnectionFactory.setPassword(pass); + return jmsConnectionFactory; + } + +} diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/OrderRoute.java b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/OrderRoute.java new file mode 100644 index 0000000..3a860a7 --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/OrderRoute.java @@ -0,0 +1,36 @@ +/* + * 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 sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.qpid.jms.JmsConnectionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class OrderRoute extends RouteBuilder { + + @Autowired + JmsConnectionFactory amqpConnectionFactory; + + @Override + public void configure() throws Exception { + from("file:src/main/data?noop=true") + .to("amqp:queue:order.queue"); + } + +} diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/WidgetGadgetApp.java b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/WidgetGadgetApp.java new file mode 100644 index 0000000..c8df269 --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/WidgetGadgetApp.java @@ -0,0 +1,11 @@ +package sample.camel; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WidgetGadgetApp { + public static void main(String[] args) { + SpringApplication.run(WidgetGadgetApp.class, args); + } +} diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/WidgetGadgetRoute.java b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/WidgetGadgetRoute.java new file mode 100644 index 0000000..e668b38 --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/java/sample/camel/WidgetGadgetRoute.java @@ -0,0 +1,26 @@ +package sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.qpid.jms.JmsConnectionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class WidgetGadgetRoute extends RouteBuilder { + + @Autowired + JmsConnectionFactory amqpConnectionFactory; + + @Override + public void configure() throws Exception { + from("amqp:queue:order.queue") + .choice() + .when().jsonpath("$.order[?(@.product=='widget')]") + .to("log:widget") + .to("amqp:queue:widget.queue") + .otherwise() + .to("log:gadget") + .to("amqp:queue:gadget.queue"); + } + +} diff --git a/examples/camel-example-spring-boot-widget-gadget/src/main/resources/application.properties b/examples/camel-example-spring-boot-widget-gadget/src/main/resources/application.properties new file mode 100644 index 0000000..398de92 --- /dev/null +++ b/examples/camel-example-spring-boot-widget-gadget/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.artemis.mode=native +AMQP_REMOTE_URI=amqp://localhost:5672 +AMQP_SERVICE_USERNAME=admin +AMQP_SERVICE_PASSWORD=admin \ No newline at end of file
