You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/03/08 10:45:47 UTC
[camel] 01/05: CAMEL-12330: Added camel-example-rabbitmq
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 441bcf2b0e9220efe0666144bcaa2c2d1e1623cb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 8 10:01:41 2018 +0100
CAMEL-12330: Added camel-example-rabbitmq
---
examples/README.adoc | 8 +-
examples/camel-example-rabbitmq/pom.xml | 151 +++++++++++++++++++++
examples/camel-example-rabbitmq/readme.adoc | 29 ++++
.../java/sample/camel/SampleCamelApplication.java | 37 +++++
.../main/java/sample/camel/SampleCamelRouter.java | 40 ++++++
.../src/main/resources/application.properties | 45 ++++++
examples/pom.xml | 1 +
7 files changed, 309 insertions(+), 2 deletions(-)
diff --git a/examples/README.adoc b/examples/README.adoc
index be893ac..04b6ee3 100644
--- a/examples/README.adoc
+++ b/examples/README.adoc
@@ -11,7 +11,7 @@ View the individual example READMEs for details.
### Examples
// examples: START
-Number of Examples: 101 (8 deprecated)
+Number of Examples: 102 (8 deprecated)
[width="100%",cols="4,2,4",options="header"]
|===
@@ -139,7 +139,9 @@ Number of Examples: 101 (8 deprecated)
| link:camel-example-activemq-tomcat/README.md[ActiveMQ Tomcat] (camel-example-activemq-tomcat) | Messaging | An example using ActiveMQ Broker and Camel with Apache Tomcat
-| link:camel-example-artemis-amqp-blueprint/README.md[Artemis Amqp Blueprint] (camel-example-artemis-amqp-blueprint) | Messaging | Demonstrates ActiveMQ Artemis using Camel's AMQP component. The example includes a JUnit showcasing how to embed for testing an AMQP enabled Artemis broker.
+| link:camel-example-artemis-amqp-blueprint/README.md[Artemis Amqp Blueprint] (camel-example-artemis-amqp-blueprint) | Messaging | Demonstrates ActiveMQ Artemis using Camel's AMQP component. The example includes a JUnit showcasing how
+ to embed for testing an AMQP enabled Artemis broker.
+
| link:camel-example-artemis-large-messages/README.md[Artemis Large Messages] (camel-example-artemis-large-messages) | Messaging | Demonstrates sending large messages (handles GBs in size) between Apache Camel and ActiveMQ Artemis in streaming mode
@@ -151,6 +153,8 @@ Number of Examples: 101 (8 deprecated)
| link:camel-example-kafka/README.adoc[Kafka] (camel-example-kafka) | Messaging | An example for Kafka
+| link:camel-example-rabbitmq/readme.adoc[Rabbitmq] (camel-example-rabbitmq) | Messaging | An example showing how to work with Camel and RabbitMQ
+
| link:camel-example-spring-boot-activemq/readme.adoc[Spring Boot Activemq] (camel-example-spring-boot-activemq) | Messaging | An example showing how to work with Camel, ActiveMQ and Spring Boot
| link:camel-example-spring-jms/README.md[Spring JMS] (camel-example-spring-jms) | Messaging | An example using Spring XML to talk to the JMS server from different kind of client techniques
diff --git a/examples/camel-example-rabbitmq/pom.xml b/examples/camel-example-rabbitmq/pom.xml
new file mode 100644
index 0000000..cfdd685
--- /dev/null
+++ b/examples/camel-example-rabbitmq/pom.xml
@@ -0,0 +1,151 @@
+<?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.21.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-rabbitmq</artifactId>
+ <name>Camel :: Example :: RabbitMQ</name>
+ <description>An example showing how to work with Camel and RabbitMQ</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>
+
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-undertow</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-actuator</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-rabbitmq-starter</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>
+
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <!-- allows to fail if not all routes are fully covered during testing -->
+<!--
+ <configuration>
+ <failOnError>true</failOnError>
+ </configuration>
+-->
+ </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-rabbitmq/readme.adoc b/examples/camel-example-rabbitmq/readme.adoc
new file mode 100644
index 0000000..c82d5d3
--- /dev/null
+++ b/examples/camel-example-rabbitmq/readme.adoc
@@ -0,0 +1,29 @@
+= Camel Example RabbitMQ
+
+This example shows how to work with a simple Apache Camel application that routes message to RabbitMQ.
+
+The example generates messages using timer trigger, routes them via RabbitMQ and logs to message.
+
+=== Configuring RabbitMQ
+
+The sample application uses `localhost:5672` to connect to the RabbitMQ broker.
+This can be configured in the `application.properties` file.
+
+The login information is the default `guest/guest` account, which can be configured
+in the `application.properties` file as well.
+
+== How to run
+
+The sample requires a RabbitMQ broker to be running.
+
+You can for example easily start RabbitMQ via Docker
+
+ docker run -it -p 5672:5672 --hostname my-rabbit --name some-rabbit rabbitmq:3
+
+Then 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/
diff --git a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
new file mode 100644
index 0000000..5d9304a
--- /dev/null
+++ b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelApplication.java
@@ -0,0 +1,37 @@
+/**
+ * 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.SpringBootApplication;
+
+//CHECKSTYLE:OFF
+/**
+ * A sample Spring Boot application that starts the Camel routes.
+ */
+@SpringBootApplication
+public class SampleCamelApplication {
+
+ /**
+ * A main method to start this application.
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(SampleCamelApplication.class, args);
+ }
+
+}
+//CHECKSTYLE:ON
diff --git a/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
new file mode 100644
index 0000000..aff28f9
--- /dev/null
+++ b/examples/camel-example-rabbitmq/src/main/java/sample/camel/SampleCamelRouter.java
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+/**
+ * A simple Camel route that triggers from a timer and routes to RabbitMQ
+ * <p/>
+ * Use <tt>@Component</tt> to make Camel auto detect this route when starting.
+ */
+@Component
+public class SampleCamelRouter extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("timer:hello?period=1000")
+ .transform(simple("Random number ${random(0,100)}"))
+ .to("rabbitmq:{{rabbit-host}}:{{rabbit-port}}/foo?username={{rabbit-user}}&password={{rabbit-password}}");
+
+ from("rabbitmq:{{rabbit-host}}:{{rabbit-port}}/foo?username={{rabbit-user}}&password={{rabbit-password}}")
+ .log("From RabbitMQ: ${body}");
+ }
+
+}
diff --git a/examples/camel-example-rabbitmq/src/main/resources/application.properties b/examples/camel-example-rabbitmq/src/main/resources/application.properties
new file mode 100644
index 0000000..7d7c800
--- /dev/null
+++ b/examples/camel-example-rabbitmq/src/main/resources/application.properties
@@ -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.
+## ---------------------------------------------------------------------------
+
+# the name of Camel
+camel.springboot.name = SampleCamel
+
+# to automatic shutdown the JVM after a period of time
+#camel.springboot.duration-max-seconds=60
+#camel.springboot.duration-max-messages=100
+
+# add for example: &repeatCount=5 to the timer endpoint to make Camel idle
+#camel.springboot.duration-max-idle-seconds=15
+
+# properties used in the Camel route and beans
+# --------------------------------------------
+
+# all access to actuator endpoints without security
+management.security.enabled = false
+# turn on actuator health check
+endpoints.health.enabled = true
+
+rabbit-host=localhost
+rabbit-port=5672
+rabbit-user=guest
+rabbit-password=guest
+
+# to configure logging levels
+#logging.level.org.springframework = INFO
+#logging.level.org.apache.camel.spring.boot = INFO
+#logging.level.org.apache.camel.impl = DEBUG
+#logging.level.sample.camel = DEBUG
diff --git a/examples/pom.xml b/examples/pom.xml
index 50a1eda..5c55f5e 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -80,6 +80,7 @@
<module>camel-example-olingo4-blueprint</module>
<module>camel-example-opentracing</module>
<module>camel-example-pojo-messaging</module>
+ <module>camel-example-rabbitmq</module>
<module>camel-example-reactive-streams</module>
<module>camel-example-reload</module>
<module>camel-example-reportincident</module>
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.