This is an automated email from the ASF dual-hosted git repository.
ramu12 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new dcbfd04 CAMEL-13138:camel-spring-boot - Example with using
camel-amqp-starter
dcbfd04 is described below
commit dcbfd04bda02e4ae988af1e014d4baccced1a1bb
Author: Ramu <[email protected]>
AuthorDate: Thu Mar 7 08:11:30 2019 +0530
CAMEL-13138:camel-spring-boot - Example with using camel-amqp-starter
---
examples/camel-example-spring-boot-amqp/pom.xml | 152 +++++++++++++++++++++
.../camel-example-spring-boot-amqp/readme.adoc | 30 ++++
.../src/main/data/ReadMe.txt | 43 ++++++
.../src/main/java/sample/camel/AmqpConfig.java | 86 ++++++++++++
.../java/sample/camel/SampleAmqApplication.java | 32 +++++
.../sample/camel/SampleAutowiredAmqpRoute.java | 46 +++++++
.../src/main/resources/application.properties | 25 ++++
.../sample/camel/SampleAmqApplicationTests.java | 43 ++++++
8 files changed, 457 insertions(+)
diff --git a/examples/camel-example-spring-boot-amqp/pom.xml
b/examples/camel-example-spring-boot-amqp/pom.xml
new file mode 100644
index 0000000..20a73c3b
--- /dev/null
+++ b/examples/camel-example-spring-boot-amqp/pom.xml
@@ -0,0 +1,152 @@
+<?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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-spring-boot-amqp</artifactId>
+ <name>Camel :: Example :: Spring Boot :: Amqp</name>
+ <description>An example showing how to work with Camel, ActiveMQ Amqp and
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</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</groupId>
+ <artifactId>camel-amqp-starter</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-amqp</artifactId>
+ </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>
+ <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>
+
+ <profiles>
+ <profile>
+ <id>jdk9+-build</id>
+ <activation>
+ <jdk>[9,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>--add-modules java.xml.bind --add-opens
+ java.base/java.lang=ALL-UNNAMED</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/examples/camel-example-spring-boot-amqp/readme.adoc
b/examples/camel-example-spring-boot-amqp/readme.adoc
new file mode 100644
index 0000000..33e2d0a
--- /dev/null
+++ b/examples/camel-example-spring-boot-amqp/readme.adoc
@@ -0,0 +1,30 @@
+# Camel Example Spring Boot and ActiveMQ AMQP
+
+This example shows how to work with a simple Apache Camel application using
Spring Boot and Apache ActiveMQ.
+
+## Preparing ActiveMQ brokers
+
+From Apache ActiveMQ you can download the broker as a .zip or .tar.gz file.
+
+Unzip/tar the archive, and start a terminal.
+
+Change directory to the unzipped directory and start the broker.
+
+ bin/activemq console
+
+Which runs the broker in the foreground and logs to the console.
+
+## How to run the example
+
+You can run this example using
+
+ mvn spring-boot:run
+
+## Using Camel components
+
+Apache Camel provides 200+ components which you can use to integrate and route
messages between many systems
+and data formats. To use any of these Camel components, add the component as a
dependency to your project.
+
+## More information
+
+You can find more information about Apache Camel at the website:
http://camel.apache.org/
diff --git a/examples/camel-example-spring-boot-amqp/src/main/data/ReadMe.txt
b/examples/camel-example-spring-boot-amqp/src/main/data/ReadMe.txt
new file mode 100644
index 0000000..c384fbd
--- /dev/null
+++ b/examples/camel-example-spring-boot-amqp/src/main/data/ReadMe.txt
@@ -0,0 +1,43 @@
+example project which connects to A-MQ 7 from Fuse 7, using remote A-MQ address
+
+There is the code, from that project, which instantiates component, and sends
message
+
+public class CamelRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ JmsComponent component = createArtemisComponent();
+ getContext().addComponent("artemis", component);
+
+
from("timer://foo?fixedRate=true&period=60000&repeatCount=2")
+ .setBody().constant("HELLO")
+ .to("artemis:queue:test")
+ .log("Sent --> ${body}")
+ ;
+ }
+
+ private JmsComponent createArtemisComponent() {
+
+ ActiveMQJMSConnectionFactory connectionFactory= new
ActiveMQJMSConnectionFactory("tcp://localhost:61616");
+ connectionFactory.setUser("admin");
+ connectionFactory.setPassword("admin");
+
+ JmsComponent component = new JmsComponent();
+ component.setConnectionFactory(connectionFactory);
+
+ return component;
+ }
+}
+
+Please see pom file, I don't specify pom versions, because they come in the BOM
+
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-jms-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jms</artifactId>
+ </dependency>
+
+
diff --git
a/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/AmqpConfig.java
b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/AmqpConfig.java
new file mode 100644
index 0000000..9d3928e
--- /dev/null
+++
b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/AmqpConfig.java
@@ -0,0 +1,86 @@
+/**
+ * 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.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class AmqpConfig {
+
+ @Value("${AMQP_HOST}")
+ private String amqpHost;
+ @Value("${AMQP_SERVICE_PORT}")
+ private String amqpPort;
+ @Value("${AMQP_SERVICE_USERNAME}")
+ private String userName;
+ @Value("${AMQP_SERVICE_PASSWORD}")
+ private String pass;
+ @Value("${AMQP_REMOTE_URI}")
+ private String remoteUri;
+
+ public String getAmqpHost() {
+ return amqpHost;
+ }
+
+ public void setAmqpHost(String amqpHost) {
+ this.amqpHost = amqpHost;
+ }
+
+ public String getAmqpPort() {
+ return amqpPort;
+ }
+
+ public void setAmqpPort(String amqpPort) {
+ this.amqpPort = amqpPort;
+ }
+
+ 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 org.apache.qpid.jms.JmsConnectionFactory amqpConnectionFactory() {
+ org.apache.qpid.jms.JmsConnectionFactory jmsConnectionFactory = new
org.apache.qpid.jms.JmsConnectionFactory();
+ jmsConnectionFactory.setRemoteURI(remoteUri);
+ jmsConnectionFactory.setUsername(userName);
+ jmsConnectionFactory.setPassword(pass);
+ return jmsConnectionFactory;
+ }
+
+}
diff --git
a/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAmqApplication.java
b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAmqApplication.java
new file mode 100644
index 0000000..41353e4
--- /dev/null
+++
b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAmqApplication.java
@@ -0,0 +1,32 @@
+/**
+ * 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.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+//CHECKSTYLE:OFF
+@SpringBootApplication
+@EnableAutoConfiguration
+public class SampleAmqApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SampleAmqApplication.class, args);
+ }
+}
+// CHECKSTYLE:ON
diff --git
a/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAutowiredAmqpRoute.java
b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAutowiredAmqpRoute.java
new file mode 100644
index 0000000..180e092
--- /dev/null
+++
b/examples/camel-example-spring-boot-amqp/src/main/java/sample/camel/SampleAutowiredAmqpRoute.java
@@ -0,0 +1,46 @@
+/**
+ * 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.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SampleAutowiredAmqpRoute extends RouteBuilder {
+
+ @Autowired JmsConnectionFactory amqpConnectionFactory;
+ @Bean
+ public org.apache.camel.component.amqp.AMQPComponent amqpConnection() {
+ org.apache.camel.component.amqp.AMQPComponent amqp = new
org.apache.camel.component.amqp.AMQPComponent();
+ amqp.setConnectionFactory(amqpConnectionFactory);
+ return amqp;
+ }
+
+ @Override
+ public void configure() throws Exception {
+ from("file:src/main/data?noop=true")
+ .to("amqp:queue:SCIENCEQUEUE");
+
+ /*from("timer:bar")
+ .setBody(constant("Hello from Camel"))
+ .to("amqp:queue:SCIENCEQUEUE");*/
+ }
+
+}
diff --git
a/examples/camel-example-spring-boot-amqp/src/main/resources/application.properties
b/examples/camel-example-spring-boot-amqp/src/main/resources/application.properties
new file mode 100644
index 0000000..e70b0d5
--- /dev/null
+++
b/examples/camel-example-spring-boot-amqp/src/main/resources/application.properties
@@ -0,0 +1,25 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#You can use this property to override the default autowired broker-url
+
+camel.springboot.main-run-controller = true
+AMQP_REMOTE_URI=amqp://localhost:5672
+AMQP_HOST=localhost
+AMQP_SERVICE_PORT=5672
+AMQP_SERVICE_USERNAME=admin
+AMQP_SERVICE_PASSWORD=admin
diff --git
a/examples/camel-example-spring-boot-amqp/src/test/java/sample/camel/SampleAmqApplicationTests.java
b/examples/camel-example-spring-boot-amqp/src/test/java/sample/camel/SampleAmqApplicationTests.java
new file mode 100644
index 0000000..e1534d8
--- /dev/null
+++
b/examples/camel-example-spring-boot-amqp/src/test/java/sample/camel/SampleAmqApplicationTests.java
@@ -0,0 +1,43 @@
+/**
+ * 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 java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.test.spring.CamelSpringBootRunner;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.Assert.assertTrue;
+
+@RunWith(CamelSpringBootRunner.class)
+@SpringBootTest(classes = SampleAmqApplication.class)
+public class SampleAmqApplicationTests {
+ @Autowired
+ private CamelContext camelContext;
+
+ @Ignore("Requires a running activemq broker")
+ public void shouldProduceMessages() throws Exception {
+ NotifyBuilder notify = new
NotifyBuilder(camelContext).whenDone(1).create();
+
+ assertTrue(notify.matches(10, TimeUnit.SECONDS));
+ }
+}