This commit is contained in:
Clebert Suconic 2018-06-18 15:53:29 -04:00
commit 47ba1f051b
11 changed files with 528 additions and 4 deletions

View File

@ -20,6 +20,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@ -58,6 +60,9 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
@Parameter(defaultValue = "${activemq.basedir}", required = true)
private File home;
@Parameter
private String[] replacePairs;
@Parameter(defaultValue = "${activemq.basedir}/artemis-distribution/target/apache-artemis-${project.version}-bin/apache-artemis-${project.version}/", required = true)
private File alternateHome;
@ -127,6 +132,12 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
@Parameter
private String[] libListWithDeps;
@Parameter
private String[] webList;
@Parameter
private String[] webListWithDeps;
@Parameter(defaultValue = "${localRepository}")
private org.apache.maven.artifact.repository.ArtifactRepository localRepository;
@ -261,7 +272,18 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
commandLineStream.println("# This is a list of files that need to be installed under ./lib.");
commandLineStream.println("# We are copying them from your maven lib home");
for (File file : files) {
copyToLib(file, commandLineStream);
copyToDir("lib", file, commandLineStream);
}
}
files = resolveDependencies(webListWithDeps, webList);
if (!files.isEmpty()) {
commandLineStream.println();
commandLineStream.println("# This is a list of files that need to be installed under ./web.");
commandLineStream.println("# We are copying them from your maven lib home");
for (File file : files) {
copyToDir("web", file, commandLineStream);
}
}
@ -282,11 +304,26 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
Path sourcePath,
Path targetPath,
PrintStream commandLineStream) throws IOException {
boolean hasReplacements = false;
if (replacePairs != null && replacePairs.length > 0) {
hasReplacements = true;
if (replacePairs.length % 2 == 1) {
throw new IllegalArgumentException("You need to pass an even number of replacement pairs");
}
for (int i = 0; i < replacePairs.length; i += 2) {
commandLineStream.println("# replace " + replacePairs[i] + " by " + replacePairs[i + 1] + " on these files");
}
}
for (String file : list) {
Path target = targetPath.resolve(file);
Path originalFile = sourcePath.resolve(file);
Files.copy(originalFile, target, StandardCopyOption.REPLACE_EXISTING);
if (hasReplacements) {
copyWithReplacements(originalFile, target);
} else {
Files.copy(originalFile, target, StandardCopyOption.REPLACE_EXISTING);
}
commandLineStream.println("");
@ -304,6 +341,16 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
}
}
private void copyWithReplacements(Path original, Path target) throws IOException {
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(original), charset);
for (int i = 0; i < replacePairs.length; i += 2) {
content = content.replaceAll(replacePairs[i], replacePairs[i + 1]);
}
Files.write(target, content.getBytes(charset));
}
private String getCommandline(ArrayList<String> listCommands) {
StringBuffer buffer = new StringBuffer();
buffer.append(home.getAbsolutePath() + "/bin/artemis ");
@ -313,8 +360,8 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
return buffer.toString();
}
private void copyToLib(File projectLib, PrintStream commandLineStream) throws IOException {
Path target = instance.toPath().resolve("lib").resolve(projectLib.getName());
private void copyToDir(String destination, File projectLib, PrintStream commandLineStream) throws IOException {
Path target = instance.toPath().resolve(destination).resolve(projectLib.getName());
File file = target.toFile();
File parent = file.getParentFile();
if (!parent.exists()) {

View File

@ -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

View File

@ -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>

View File

@ -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();
}
}
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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.

View File

@ -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>