ARTEMIS-1931 Add camel example
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/3b6c0107 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/3b6c0107 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/3b6c0107 Branch: refs/heads/master Commit: 3b6c0107397e1db208591f2238fadcc9d5b05753 Parents: e2e1034 Author: Justin Bertram <jbert...@apache.org> Authored: Fri Nov 17 12:29:48 2017 -0600 Committer: Clebert Suconic <clebertsuco...@apache.org> Committed: Mon Jun 18 15:46:35 2018 -0400 ---------------------------------------------------------------------- docs/user-manual/en/examples.md | 5 + .../standard/camel/camel-broker/pom.xml | 132 +++++++++++++++++++ .../artemis/jms/example/CamelExample.java | 102 ++++++++++++++ .../resources/activemq/server0/bootstrap.xml | 30 +++++ .../features/standard/camel/camel-war/pom.xml | 76 +++++++++++ .../main/webapp/WEB-INF/applicationContext.xml | 45 +++++++ .../camel-war/src/main/webapp/WEB-INF/web.xml | 27 ++++ examples/features/standard/camel/pom.xml | 43 ++++++ examples/features/standard/camel/readme.md | 15 +++ examples/features/standard/pom.xml | 2 + 10 files changed, 477 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/docs/user-manual/en/examples.md ---------------------------------------------------------------------- diff --git a/docs/user-manual/en/examples.md b/docs/user-manual/en/examples.md index 70d5ee0..7cd88ff 100644 --- a/docs/user-manual/en/examples.md +++ b/docs/user-manual/en/examples.md @@ -270,6 +270,11 @@ A `QueueBrowser` is used to look at messages on the queue without removing them. It can scan the entire content of a queue or only messages matching a message selector. +## Camel + +The `camel` example demonstrates how to build and deploy a Camel route to the +broker using a web application archive (i.e. `war` file). + ## Client Kickoff The `client-kickoff` example shows how to terminate client connections given an http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/camel-broker/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/camel-broker/pom.xml b/examples/features/standard/camel/camel-broker/pom.xml new file mode 100644 index 0000000..9e63f69 --- /dev/null +++ b/examples/features/standard/camel/camel-broker/pom.xml @@ -0,0 +1,132 @@ +<?xml version='1.0'?> +<!-- +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.activemq.examples.broker.camel</groupId> + <artifactId>camel</artifactId> + <version>2.7.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-broker</artifactId> + <packaging>jar</packaging> + <name>ActiveMQ Artemis Camel Broker</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../../..</activemq.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.activemq.examples.broker.camel</groupId> + <artifactId>camel-war</artifactId> + <version>${project.version}</version> + <type>war</type> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jms_2.0_spec</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>create0</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <webList> + <!-- pull in the war file from the camel-war maven module and put it into the "web" directory + so it will be deployed when the broker starts --> + <arg>org.apache.activemq.examples.broker.camel:camel-war:war:${project.version}</arg> + </webList> + <replacePairs> + <arg>WARFILE</arg> + <arg>camel-war-${project.version}.war</arg> + </replacePairs> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server0</instance> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>start0</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <location>${basedir}/target/server0</location> + <testURI>tcp://localhost:61616</testURI> + <args> + <param>run</param> + </args> + <name>server0</name> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.CamelExample</clientClass> + </configuration> + </execution> + <execution> + <id>stop0</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <location>${basedir}/target/server0</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.broker.camel</groupId> + <artifactId>camel-broker</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/camel-broker/src/main/java/org/apache/activemq/artemis/jms/example/CamelExample.java ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/camel-broker/src/main/java/org/apache/activemq/artemis/jms/example/CamelExample.java b/examples/features/standard/camel/camel-broker/src/main/java/org/apache/activemq/artemis/jms/example/CamelExample.java new file mode 100644 index 0000000..f6a71cc --- /dev/null +++ b/examples/features/standard/camel/camel-broker/src/main/java/org/apache/activemq/artemis/jms/example/CamelExample.java @@ -0,0 +1,102 @@ +/* + * 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.activemq.artemis.jms.example; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.naming.InitialContext; +import java.util.Hashtable; + +public class CamelExample { + + public static void main(final String[] args) throws Exception { + Connection connection = null; + + InitialContext ic = null; + + try { + // Step 1. - we create an initial context for looking up JNDI + + Hashtable<String, Object> properties = new Hashtable<>(); + properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); + properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:61616"); + properties.put("queue.queue/sausage-factory", "sausage-factory"); + properties.put("queue.queue/mincing-machine", "mincing-machine"); + ic = new InitialContext(properties); + + // Step 2. - we look up the sausage-factory queue from node 0 + + Queue sausageFactory = (Queue) ic.lookup("queue/sausage-factory"); + + Queue mincingMachine = (Queue) ic.lookup("queue/mincing-machine"); + + // Step 3. - we look up a JMS ConnectionFactory object from node 0 + + ConnectionFactory cf = (ConnectionFactory) ic.lookup("ConnectionFactory"); + + // Step 4. We create a JMS Connection connection which is a connection to server 0 + + connection = cf.createConnection(); + + // Step 5. We create a JMS Session on server 0 + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Step 6. We start the connection to ensure delivery occurs on them + + connection.start(); + + // Step 7. We create JMS MessageConsumer object + MessageConsumer consumer = session.createConsumer(mincingMachine); + + // Step 8. We create a JMS MessageProducer object + MessageProducer producer = session.createProducer(sausageFactory); + + // Step 9. We create and send a message to the sausage-factory + Message message = session.createMessage(); + + producer.send(message); + + System.out.println("Sent message to sausage-factory"); + + // Step 10. - we successfully receive the message from the mincing-machine. + + Message receivedMessage = consumer.receive(5000); + + if (receivedMessage == null) { + throw new IllegalStateException(); + } + + System.out.println("Received message from mincing-machine"); + } finally { + // Step 15. Be sure to close our resources! + + if (connection != null) { + connection.close(); + } + + if (ic != null) { + ic.close(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/camel-broker/src/main/resources/activemq/server0/bootstrap.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/camel-broker/src/main/resources/activemq/server0/bootstrap.xml b/examples/features/standard/camel/camel-broker/src/main/resources/activemq/server0/bootstrap.xml new file mode 100644 index 0000000..6c58a27 --- /dev/null +++ b/examples/features/standard/camel/camel-broker/src/main/resources/activemq/server0/bootstrap.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- + ~ 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. + --> + +<broker xmlns="http://activemq.org/schema"> + + <jaas-security domain="activemq"/> + + <server configuration="${artemis.URI.instance}/etc/broker.xml"/> + + <web bind="http://localhost:8080" path="web"> + <!-- ${war} is defined in the example's pom.xml --> + <app url="camel" war="WARFILE"/> + </web> +</broker> + http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/camel-war/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/camel-war/pom.xml b/examples/features/standard/camel/camel-war/pom.xml new file mode 100644 index 0000000..61e887c --- /dev/null +++ b/examples/features/standard/camel/camel-war/pom.xml @@ -0,0 +1,76 @@ +<?xml version='1.0'?> +<!-- +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.activemq.examples.broker.camel</groupId> + <artifactId>camel</artifactId> + <version>2.7.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-war</artifactId> + <packaging>war</packaging> + <name>ActiveMQ Artemis Camel WAR Application</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../../..</activemq.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${spring.version}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring</artifactId> + <version>2.20.0</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jms</artifactId> + <version>2.20.0</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jms_2.0_spec</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/applicationContext.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/applicationContext.xml b/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 0000000..d4d269c --- /dev/null +++ b/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,45 @@ +<?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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://camel.apache.org/schema/spring + http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <bean id="artemisConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> + <constructor-arg index="0" value="tcp://localhost:61616"/> + </bean> + + <bean id="artemisConfig" class="org.apache.camel.component.jms.JmsConfiguration"> + <property name="connectionFactory" ref="artemisConnectionFactory"/> + <property name="concurrentConsumers" value="10"/> + </bean> + + <bean id="artemis" class="org.apache.camel.component.jms.JmsComponent"> + <property name="configuration" ref="artemisConfig"/> + </bean> + + <camelContext id="bridgeContext" trace="false" xmlns="http://camel.apache.org/schema/spring"> + <route id="exampleRoute"> + <from uri="artemis:queue:sausage-factory"/> + <to uri="artemis:queue:mincing-machine"/> + </route> + </camelContext> +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/web.xml b/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..c5c9531 --- /dev/null +++ b/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,27 @@ +<?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. +--> +<web-app xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" + version="2.5"> + + <listener> + <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> + </listener> + +</web-app> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/pom.xml b/examples/features/standard/camel/pom.xml new file mode 100644 index 0000000..c6be9ee --- /dev/null +++ b/examples/features/standard/camel/pom.xml @@ -0,0 +1,43 @@ +<?xml version='1.0'?> +<!-- +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.activemq.examples.broker</groupId> + <artifactId>jms-examples</artifactId> + <version>2.7.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.activemq.examples.broker.camel</groupId> + <artifactId>camel</artifactId> + <packaging>pom</packaging> + <name>ActiveMQ Artemis Camel Example</name> + + <properties> + <activemq.basedir>${project.basedir}/../../../..</activemq.basedir> + </properties> + + <modules> + <module>camel-war</module> + <module>camel-broker</module> + </modules> +</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/camel/readme.md ---------------------------------------------------------------------- diff --git a/examples/features/standard/camel/readme.md b/examples/features/standard/camel/readme.md new file mode 100644 index 0000000..a39fa7c --- /dev/null +++ b/examples/features/standard/camel/readme.md @@ -0,0 +1,15 @@ +# Camel Example + +To run the example, simply type **mvn verify** from this directory, or **mvn -PnoServer verify** if you want to start and create the broker manually. + +This example contains 2 different Maven modules: + +1) `camel-broker` The module responsible for creating the broker, deploying the WAR-based Camel application, and running the client. +2) `camel-war` The module used to build the WAR-based Camel application. + +The overall goal of this example is to demonstrate how to build and deploy a Camel route to the broker. + +The client itself is essentially the same as the one in the `core-bridge` example except there is only 1 broker in this +example rather than 2. A Camel route defined in the WAR is responsible for moving messages between 2 queues. The client +sends a message to one queue, the Camel route moves that message to a second queue, and then the client reads that +message from the second queue. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3b6c0107/examples/features/standard/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/pom.xml b/examples/features/standard/pom.xml index 13e006b..0493457 100644 --- a/examples/features/standard/pom.xml +++ b/examples/features/standard/pom.xml @@ -44,6 +44,7 @@ under the License. <module>auto-closeable</module> <module>browser</module> <module>broker-plugin</module> + <module>camel</module> <module>cdi</module> <module>client-kickoff</module> <module>completion-listener</module> @@ -114,6 +115,7 @@ under the License. <module>auto-closeable</module> <module>browser</module> <module>broker-plugin</module> + <module>camel</module> <module>cdi</module> <module>client-kickoff</module> <module>completion-listener</module>