diff --git a/docs/user-manual/en/examples.md b/docs/user-manual/en/examples.md index 70d5ee0d8d..7cd88ff6e9 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 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 0000000000..9e63f69814 --- /dev/null +++ b/examples/features/standard/camel/camel-broker/pom.xml @@ -0,0 +1,132 @@ + + + + + 4.0.0 + + + org.apache.activemq.examples.broker.camel + camel + 2.7.0-SNAPSHOT + + + camel-broker + jar + ActiveMQ Artemis Camel Broker + + + ${project.basedir}/../../../../.. + + + + + org.apache.activemq + artemis-server + ${project.version} + + + org.apache.activemq.examples.broker.camel + camel-war + ${project.version} + war + + + org.apache.geronimo.specs + geronimo-jms_2.0_spec + + + + + + + org.apache.activemq + artemis-maven-plugin + ${project.version} + + + create0 + + create + + + + + org.apache.activemq.examples.broker.camel:camel-war:war:${project.version} + + + WARFILE + camel-war-${project.version}.war + + ${noServer} + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + runClient + + runClient + + + org.apache.activemq.artemis.jms.example.CamelExample + + + + stop0 + + cli + + + ${noServer} + ${basedir}/target/server0 + + stop + + + + + + + org.apache.activemq.examples.broker.camel + camel-broker + ${project.version} + + + + + + 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 0000000000..f6a71cc893 --- /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 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(); + } + } + } +} 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 0000000000..6c58a273d7 --- /dev/null +++ b/examples/features/standard/camel/camel-broker/src/main/resources/activemq/server0/bootstrap.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 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 0000000000..61e887cfa5 --- /dev/null +++ b/examples/features/standard/camel/camel-war/pom.xml @@ -0,0 +1,76 @@ + + + + + 4.0.0 + + + org.apache.activemq.examples.broker.camel + camel + 2.7.0-SNAPSHOT + + + camel-war + war + ActiveMQ Artemis Camel WAR Application + + + ${project.basedir}/../../../../.. + + + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-context + + + org.apache.camel + camel-spring + 2.20.0 + + + org.slf4j + slf4j-api + + + + + org.apache.camel + camel-jms + 2.20.0 + + + org.slf4j + slf4j-api + + + org.apache.geronimo.specs + geronimo-jms_2.0_spec + + + + + + 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 0000000000..d4d269c1b3 --- /dev/null +++ b/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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 0000000000..c5c9531b72 --- /dev/null +++ b/examples/features/standard/camel/camel-war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,27 @@ + + + + + + org.springframework.web.context.ContextLoaderListener + + + \ No newline at end of file diff --git a/examples/features/standard/camel/pom.xml b/examples/features/standard/camel/pom.xml new file mode 100644 index 0000000000..c6be9ee10a --- /dev/null +++ b/examples/features/standard/camel/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + + org.apache.activemq.examples.broker + jms-examples + 2.7.0-SNAPSHOT + + + org.apache.activemq.examples.broker.camel + camel + pom + ActiveMQ Artemis Camel Example + + + ${project.basedir}/../../../.. + + + + camel-war + camel-broker + + diff --git a/examples/features/standard/camel/readme.md b/examples/features/standard/camel/readme.md new file mode 100644 index 0000000000..a39fa7cb11 --- /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 diff --git a/examples/features/standard/pom.xml b/examples/features/standard/pom.xml index 13e006b185..0493457d8b 100644 --- a/examples/features/standard/pom.xml +++ b/examples/features/standard/pom.xml @@ -44,6 +44,7 @@ under the License. auto-closeable browser broker-plugin + camel cdi client-kickoff completion-listener @@ -114,6 +115,7 @@ under the License. auto-closeable browser broker-plugin + camel cdi client-kickoff completion-listener