CAMEL-11311: Spring Boot with external ActiveMQ broker.

Showing problems using SB autowiring of Amq ConnecionFactory

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9e611463
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9e611463
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9e611463

Branch: refs/heads/master
Commit: 9e611463f2c6c44a3f9112842f07de95f800a62c
Parents: a055cd1
Author: Preben Asmussen <preben.asmus...@gmail.com>
Authored: Mon May 22 22:00:47 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu May 25 13:57:51 2017 +0200

----------------------------------------------------------------------
 examples/camel-example-spring-boot-amq/pom.xml  | 131 +++++++++++++++++++
 .../camel-example-spring-boot-amq/readme.adoc   |  23 ++++
 .../java/sample/camel/SampleAmqApplication.java |  32 +++++
 .../sample/camel/SampleAutowiredAmqRoute.java   |  35 +++++
 .../src/main/resources/application.properties   |  17 +++
 .../sample/camel/SampleAmqApplicationTests.java |  43 ++++++
 examples/pom.xml                                |   1 +
 7 files changed, 282 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/camel-example-spring-boot-amq/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-amq/pom.xml 
b/examples/camel-example-spring-boot-amq/pom.xml
new file mode 100644
index 0000000..227b49b
--- /dev/null
+++ b/examples/camel-example-spring-boot-amq/pom.xml
@@ -0,0 +1,131 @@
+<?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</groupId>
+    <artifactId>examples</artifactId>
+    <version>2.20.0-SNAPSHOT</version>
+  </parent>
+
+  <name>Camel :: Example :: Spring Boot</name>
+  <description>An example showing how to work with Camel, ActiveMq and Spring 
Boot</description>
+
+  <properties>
+    <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>
+    <!-- activemq -->
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-activemq</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.activemq</groupId>
+          <artifactId>activemq-broker</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <!-- Camel -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring-boot-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-camel</artifactId>
+      <!-- version>5.14.0</version-->
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.activemq</groupId>
+          <artifactId>activemq-broker</artifactId>
+        </exclusion>
+      </exclusions>
+    </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>
+
+
+  <artifactId>camel-example-spring-boot-amq</artifactId>
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/camel-example-spring-boot-amq/readme.adoc
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-amq/readme.adoc 
b/examples/camel-example-spring-boot-amq/readme.adoc
new file mode 100644
index 0000000..c3634ad
--- /dev/null
+++ b/examples/camel-example-spring-boot-amq/readme.adoc
@@ -0,0 +1,23 @@
+# Camel Example Spring Boot and ActiveMQ
+
+This example shows how to work with a simple Apache Camel application using 
Spring Boot and Apache ActiveMQ starter
+
+##prerequisites
+A running Apache ActiveMQ instance with openwire transportConnector opened on 
port 1234
+
+The port is also configured in application.properties as 
spring.activemq.broker-url 
+
+## 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.
+
+## How to run
+
+You can run this example using
+
+    mvn spring-boot:run
+
+## More information
+
+You can find more information about Apache Camel at the website: 
http://camel.apache.org/

http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAmqApplication.java
----------------------------------------------------------------------
diff --git 
a/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAmqApplication.java
 
b/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAmqApplication.java
new file mode 100644
index 0000000..2442c2f
--- /dev/null
+++ 
b/examples/camel-example-spring-boot-amq/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

http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAutowiredAmqRoute.java
----------------------------------------------------------------------
diff --git 
a/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAutowiredAmqRoute.java
 
b/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAutowiredAmqRoute.java
new file mode 100644
index 0000000..5746a60
--- /dev/null
+++ 
b/examples/camel-example-spring-boot-amq/src/main/java/sample/camel/SampleAutowiredAmqRoute.java
@@ -0,0 +1,35 @@
+/**
+ * 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.springframework.stereotype.Component;
+
+@Component
+public class SampleAutowiredAmqRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("activemq:foo")
+            .to("log:sample");
+
+        from("timer:bar")
+            .setBody(constant("hello from camel"))
+            .to("activemq:foo");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/camel-example-spring-boot-amq/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git 
a/examples/camel-example-spring-boot-amq/src/main/resources/application.properties
 
b/examples/camel-example-spring-boot-amq/src/main/resources/application.properties
new file mode 100644
index 0000000..6aafea1
--- /dev/null
+++ 
b/examples/camel-example-spring-boot-amq/src/main/resources/application.properties
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.activemq.broker-url=tcp://localhost:1234
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/camel-example-spring-boot-amq/src/test/java/sample/camel/SampleAmqApplicationTests.java
----------------------------------------------------------------------
diff --git 
a/examples/camel-example-spring-boot-amq/src/test/java/sample/camel/SampleAmqApplicationTests.java
 
b/examples/camel-example-spring-boot-amq/src/test/java/sample/camel/SampleAmqApplicationTests.java
new file mode 100644
index 0000000..b5cd520
--- /dev/null
+++ 
b/examples/camel-example-spring-boot-amq/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 with openwire port 1234")
+    public void shouldProduceMessages() throws Exception {
+        NotifyBuilder notify = new 
NotifyBuilder(camelContext).whenDone(1).create();
+
+        assertTrue(notify.matches(10, TimeUnit.SECONDS));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9e611463/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 4ed89df..9701d02 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -94,6 +94,7 @@
     <module>camel-example-splunk</module>
     <module>camel-example-spring</module>
     <module>camel-example-spring-boot</module>
+    <module>camel-example-spring-boot-amq</module>
     <module>camel-example-spring-boot-geocoder</module>
     <module>camel-example-spring-boot-live-reload</module>
     <module>camel-example-spring-boot-metrics</module>

Reply via email to