You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/08/07 21:31:35 UTC
[16/18] activemq-artemis git commit: ARTEMIS-180 removing -Pexample
and some other improvements around the examples
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/application-layer-failover/pom.xml
----------------------------------------------------------------------
diff --git a/examples/jms/application-layer-failover/pom.xml b/examples/jms/application-layer-failover/pom.xml
index 65d217d..b670d18 100644
--- a/examples/jms/application-layer-failover/pom.xml
+++ b/examples/jms/application-layer-failover/pom.xml
@@ -18,7 +18,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
- <artifactId>artemis-jms-application-layer-failover-example</artifactId>
+ <artifactId>application-layer-failover</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Application Layer Failover Example</name>
@@ -42,64 +43,60 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jms_2.0_spec</artifactId>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-jms-client</artifactId>
+ <version>${project.version}</version>
</dependency>
</dependencies>
- <profiles>
- <profile>
- <id>example</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create0</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server0</instance>
- </configuration>
- </execution>
- <execution>
- <id>create1</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server1</instance>
- <portOffset>1</portOffset>
- </configuration>
- </execution>
- <execution>
- <id>runClient</id>
- <goals>
- <goal>runClient</goal>
- </goals>
- <configuration>
- <clientClass>org.apache.activemq.artemis.jms.example.ApplicationLayerFailoverExample</clientClass>
- <args>
- <param>${basedir}/target/server0</param>
- <param>${basedir}/target/server1</param>
- </args>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.apache.activemq.examples.jms</groupId>
- <artifactId>artemis-jms-application-layer-failover-example</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create0</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <instance>${basedir}/target/server0</instance>
+ </configuration>
+ </execution>
+ <execution>
+ <id>create1</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <instance>${basedir}/target/server1</instance>
+ <portOffset>1</portOffset>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runClient</id>
+ <goals>
+ <goal>runClient</goal>
+ </goals>
+ <configuration>
+ <clientClass>org.apache.activemq.artemis.jms.example.ApplicationLayerFailoverExample</clientClass>
+ <args>
+ <param>${basedir}/target/server0</param>
+ <param>${basedir}/target/server1</param>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq.examples.jms</groupId>
+ <artifactId>application-layer-failover</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/application-layer-failover/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/application-layer-failover/readme.html b/examples/jms/application-layer-failover/readme.html
index b9699bc..3a23b62 100644
--- a/examples/jms/application-layer-failover/readme.html
+++ b/examples/jms/application-layer-failover/readme.html
@@ -27,6 +27,8 @@ under the License.
<body onload="prettyPrint()">
<h1>Application-Layer Failover Example</h1>
+ <pre>To run the example, simply type <b>mvn verify</b> from this directory. This example will always spawn and stop multiple servers.</pre>
+
<p>ActiveMQ Artemis implements fully transparent <b>automatic</b> failover of connections from a live node to a backup node which requires
no special coding. This is described in a different example and requires server replication.</p>
<p>However, ActiveMQ Artemis also supports <b>Application-Layer</b> failover which is useful in the case where replication is not enabled.</p>
@@ -37,12 +39,11 @@ under the License.
<p>Application-Layer failover is an alternative approach to High Availabilty (HA).</p>
<p>Application-Layer failover differs from automatic failover in that some client side coding is required in order
to implement this. Also, with Application-Layer failover, since the old Session object dies and a new is created, any uncommitted
- work in the old Session will be lost, and any unacknowledged messages might be redelivered.</p>
+ work in the old Session will be lost, and any unacknowledged messages might be redelivered.</p>
<p>For more information on ActiveMQ Artemis failover and HA, and clustering in general, please see the clustering
- section of the user manual.</p>
+ section of the user manual.</p>
<h2>Example step-by-step</h2>
- <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p>
<p>In this example, the live server is server 1, which will failover onto server 0.</p>
<p>The connection will initially be created to server1, server 1 will crash, and the client will carry on
on server 0, the new server. With Application-Layer failover the node that is failed over onto, does not need to
@@ -87,13 +88,13 @@ under the License.
}
</code>
</pre>
-
+
<li>We now cause server 1, the live server to crash. After a little while the connection's
ExceptionListener will register the failure and reconnection will occur.</li>
<pre class="prettyprint">
<code>killServer(1);</code>
</pre>
-
+
<li>The connection's ExceptionListener gets called, and we lookup the JMS objects and
recreate the connection, session, etc on the other node 0.</li>
<pre class="prettyprint">
@@ -121,7 +122,7 @@ under the License.
e.printStackTrace();
}
}
- }
+ }
</code>
</pre>
@@ -138,7 +139,7 @@ under the License.
}
</code>
</pre>
-
+
<li>And consume them.</li>
<pre class="prettyprint">
<code>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
----------------------------------------------------------------------
diff --git a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
index fcd3cca..86a2339 100644
--- a/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
+++ b/examples/jms/application-layer-failover/src/main/java/org/apache/activemq/artemis/jms/example/ApplicationLayerFailoverExample.java
@@ -16,14 +16,6 @@
*/
package org.apache.activemq.artemis.jms.example;
-import org.apache.activemq.artemis.util.ServerUtil;
-
-import java.lang.Object;
-import java.lang.String;
-import java.util.Hashtable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.ExceptionListener;
@@ -35,6 +27,11 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.util.ServerUtil;
/**
* A simple example that demonstrates application-layer failover of the JMS connection from one node to another
@@ -144,32 +141,25 @@ public class ApplicationLayerFailoverExample
private static void createJMSObjects(final int server) throws Exception
{
- // Step 1. Get an initial context for looking up JNDI from the server
- Hashtable<String, Object> properties = new Hashtable<String, Object>();
- properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
- properties.put("connectionFactory.ConnectionFactory", "tcp://127.0.0.1:" + (61616 + server));
- properties.put("queue.queue/exampleQueue", "exampleQueue");
- initialContext = new InitialContext(properties);
+ // Step 1. Instantiate a JMS Connection Factory object from JNDI on server 1
+ ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:" + (61616 + server));
- // Step 2. Look-up the JMS Queue object from JNDI
- Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
-
- // Step 3. Look-up a JMS Connection Factory object from JNDI on server 1
- ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("ConnectionFactory");
-
- // Step 4. We create a JMS Connection connection
+ // Step 2. We create a JMS Connection connection
connection = connectionFactory.createConnection();
- // Step 6. We start the connection to ensure delivery occurs
+ // Step 3. We start the connection to ensure delivery occurs
connection.start();
- // Step 5. We create a JMS Session
+ // Step 4. We create a JMS Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- // Step 7. We create a JMS MessageConsumer object
+ // Step 5. Look-up the JMS Queue object from JNDI
+ Queue queue = session.createQueue("exampleQueue");
+
+ // Step 6. We create a JMS MessageConsumer object
consumer = session.createConsumer(queue);
- // Step 8. We create a JMS MessageProducer object
+ // Step 7. We create a JMS MessageProducer object
producer = session.createProducer(queue);
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/bridge/pom.xml
----------------------------------------------------------------------
diff --git a/examples/jms/bridge/pom.xml b/examples/jms/bridge/pom.xml
index 73cbdc5..8c835de 100644
--- a/examples/jms/bridge/pom.xml
+++ b/examples/jms/bridge/pom.xml
@@ -18,7 +18,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
- <artifactId>artemis-jms-core-bridge-example</artifactId>
+ <artifactId>core-bridge</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis Core Bridge Example</name>
@@ -49,109 +50,127 @@ under the License.
<profiles>
<profile>
- <id>example</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create0</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server0</instance>
- <configuration>${basedir}/target/classes/activemq/server0</configuration>
- </configuration>
- </execution>
- <execution>
- <id>create1</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server1</instance>
- <configuration>${basedir}/target/classes/activemq/server1</configuration>
- <portOffset>1</portOffset>
- </configuration>
- </execution>
- <execution>
- <id>start0</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <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>start1</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <spawn>true</spawn>
- <location>${basedir}/target/server1</location>
- <testURI>tcp://localhost:61617</testURI>
- <args>
- <param>run</param>
- </args>
- <name>server1</name>
- </configuration>
- </execution>
- <execution>
- <id>runClient</id>
- <goals>
- <goal>runClient</goal>
- </goals>
- <configuration>
- <clientClass>org.apache.activemq.artemis.jms.example.BridgeExample</clientClass>
- </configuration>
- </execution>
- <execution>
- <id>stop0</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <location>${basedir}/target/server0</location>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- <execution>
- <id>stop1</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <location>${basedir}/target/server1</location>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.apache.activemq.examples.jms</groupId>
- <artifactId>artemis-jms-core-bridge-example</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
+ <!-- specify -PnoServer if you don't want to start the server -->
+ <id>noServer</id>
+ <properties>
+ <noServer>true</noServer>
+ </properties>
</profile>
</profiles>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create0</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <libList>
+ <!-- For the transformer -->
+ <arg>org.apache.activemq.examples.jms:core-bridge:${project.version}</arg>
+ </libList>
+ <ignore>${noServer}</ignore>
+ <instance>${basedir}/target/server0</instance>
+ <configuration>${basedir}/target/classes/activemq/server0</configuration>
+ </configuration>
+ </execution>
+ <execution>
+ <id>create1</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <libList>
+ <!-- For the transformer -->
+ <arg>org.apache.activemq.examples.jms:core-bridge:${project.version}</arg>
+ </libList>
+ <ignore>${noServer}</ignore>
+ <instance>${basedir}/target/server1</instance>
+ <configuration>${basedir}/target/classes/activemq/server1</configuration>
+ <portOffset>1</portOffset>
+ </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>start1</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <spawn>true</spawn>
+ <location>${basedir}/target/server1</location>
+ <testURI>tcp://localhost:61617</testURI>
+ <args>
+ <param>run</param>
+ </args>
+ <name>server1</name>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runClient</id>
+ <goals>
+ <goal>runClient</goal>
+ </goals>
+ <configuration>
+ <clientClass>org.apache.activemq.artemis.jms.example.BridgeExample</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>
+ <execution>
+ <id>stop1</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <location>${basedir}/target/server1</location>
+ <args>
+ <param>stop</param>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq.examples.jms</groupId>
+ <artifactId>core-bridge</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/bridge/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/bridge/readme.html b/examples/jms/bridge/readme.html
index 6b5bb01..a9440c7 100644
--- a/examples/jms/bridge/readme.html
+++ b/examples/jms/bridge/readme.html
@@ -26,6 +26,7 @@ under the License.
</head>
<body onload="prettyPrint()">
<h1>Core Bridge Example</h1>
+ <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
<p>This example demonstrates a core bridge deployed on one server, which consumes messages from a
local queue and forwards them to an address on a second server.</p>
@@ -69,166 +70,5 @@ under the License.
</bridge>
</code>
</pre>
- <h2>Example step-by-step</h2>
- <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p>
-
- <ol>
- <li>We create an initial context for looking up JNDI on node 0</li>
- <pre class="prettyprint">
- <code>
- ic0 = getContext(0);
- </code>
- </pre>
-
- <li>We look up the sausage-factory queue from node 0</li>
- <pre class="prettyprint">
- <code>Queue sausageFactory = (Queue)ic0.lookup("/queue/sausage-factory");</code>
- </pre>
-
- <li>We look up a JMS ConnectionFactory object from node 0</li>
- <pre class="prettyprint">
- <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li>We create an initial context for looking up JNDI on node 1</li>
- <pre class="prettyprint">
- <code>ic1 = getContext(1);</code>
- </pre>
-
- <li>We look up the mincing-machine queue on node 1</li>
- <pre class="prettyprint">
- <code>Queue mincingMachine = (Queue)ic1.lookup("/queue/mincing-machine");
- </code>
- </pre>
-
- <li>We look up a JMS ConnectionFactory object from node 1</li>
- <pre class="prettyprint">
- <code>
- ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
- </code>
- </pre>
-
- <li>We create a JMS Connection connection0 which is a connection to server 0</li>
- <pre class="prettyprint">
- <code>
- connection0 = cf0.createConnection();
- </code>
- </pre>
-
- <li>We create a JMS Connection connection1 which is a connection to server 1</li>
- <pre class="prettyprint">
- <code>
- connection1 = cf1.createConnection();
- </code>
- </pre>
-
- <li>We create a JMS Session on server 0</li>
- <pre class="prettyprint">
- <code>
- Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
- </code>
- </pre>
-
- <li>We create a JMS Session on server 1</li>
- <pre class="prettyprint">
- <code>
- Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
- </code>
- </pre>
-
- <li>We start the connection to ensure delivery occurs on them</li>
- <pre class="prettyprint">
- <code>
- connection1.start();
- </code>
- </pre>
-
- <li>We create a JMS MessageConsumer object on server 1</li>
- <pre class="prettyprint">
- <code>
- MessageConsumer consumer = session1.createConsumer(mincingMachine);
- </code>
- </pre>
-
- <li>We create a JMS MessageProducer object on server 0.</li>
- <pre class="prettyprint">
- <code>
- MessageProducer producer = session0.createProducer(sausageFactory);</code>
- </pre>
-
- <li>We create and send a message representing an aardvark with a green hat to the sausage-factory
- on node 0</li>
- <pre class="prettyprint">
- <code>
- Message message = session0.createMessage();
-
- message.setStringProperty("name", "aardvark");
-
- message.setStringProperty("hat", "green");
-
- producer.send(message);
- </code>
- </pre>
-
- <li>We successfully receive the aardvark message from the mincing-machine one node 1. The aardvark's
- hat is now blue since it has been transformed!</li>
- <pre class="prettyprint">
- <code>
- Message receivedMessage = consumer.receive(5000);
- </code>
- </pre>
-
- <li>We create and send another message, this time representing a sasquatch with a mauve hat to the
- sausage-factory on node 0. This won't be bridged to the mincing-machine since we only want aardvarks, not sasquatches.</li>
- <pre class="prettyprint">
- <code>
- message = session0.createMessage();
-
- message.setStringProperty("name", "sasquatch");
-
- message.setStringProperty("hat", "mauve");
-
- producer.send(message);
- </code>
- </pre>
-
- <li>We don't receive the sasquatch message since it's not an aardvark!</li>
- <pre class="prettyprint">
- <code>
- receivedMessage = (TextMessage)consumer.receive(1000);
- </code>
- </pre>
-
-
- <li>And finally (no pun intended), <b>always</b> remember to close your JMS resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre class="prettyprint">
- <code>
- finally
- {
- if (connection0 != null)
- {
- connection0.close();
- }
-
- if (connection1 != null)
- {
- connection1.close();
- }
-
- if (ic0 != null)
- {
- ic0.close();
- }
-
- if (ic1 != null)
- {
- ic1.close();
- }
- }
- </code>
- </pre>
-
- </ol>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/browser/pom.xml
----------------------------------------------------------------------
diff --git a/examples/jms/browser/pom.xml b/examples/jms/browser/pom.xml
index adaf222..8cbd2d7 100644
--- a/examples/jms/browser/pom.xml
+++ b/examples/jms/browser/pom.xml
@@ -18,7 +18,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
- <artifactId>artemis-jms-browser-example</artifactId>
+ <artifactId>browser</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Browser Example</name>
@@ -37,72 +38,82 @@ under the License.
<dependencies>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jms_2.0_spec</artifactId>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-jms-client</artifactId>
+ <version>${project.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
- <id>example</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create</id>
- <phase>verify</phase>
- <goals>
- <goal>create</goal>
- </goals>
- </execution>
- <execution>
- <id>start</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <spawn>true</spawn>
- <testURI>tcp://localhost:61616</testURI>
- <args>
- <param>run</param>
- </args>
- </configuration>
- </execution>
- <execution>
- <id>runClient</id>
- <goals>
- <goal>runClient</goal>
- </goals>
- <configuration>
- <clientClass>org.apache.activemq.artemis.jms.example.QueueBrowserExample</clientClass>
- </configuration>
- </execution>
- <execution>
- <id>stop</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.apache.activemq.examples.jms</groupId>
- <artifactId>artemis-jms-browser-example</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
+ <!-- specify -PnoServer if you don't want to start the server -->
+ <id>noServer</id>
+ <properties>
+ <noServer>true</noServer>
+ </properties>
</profile>
</profiles>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create</id>
+ <phase>verify</phase>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ </configuration>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>start</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <spawn>true</spawn>
+ <ignore>${noServer}</ignore>
+ <testURI>tcp://localhost:61616</testURI>
+ <args>
+ <param>run</param>
+ </args>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runClient</id>
+ <goals>
+ <goal>runClient</goal>
+ </goals>
+ <configuration>
+ <clientClass>org.apache.activemq.artemis.jms.example.QueueBrowserExample</clientClass>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <args>
+ <param>stop</param>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq.examples.jms</groupId>
+ <artifactId>browser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/browser/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/browser/readme.html b/examples/jms/browser/readme.html
index b960ff4..76f349f 100644
--- a/examples/jms/browser/readme.html
+++ b/examples/jms/browser/readme.html
@@ -26,122 +26,15 @@ under the License.
</head>
<body onload="prettyPrint()">
<h1>JMS QueueBrowser Example</h1>
+ <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
<p>This example shows you how to use a JMS <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/QueueBrowser.html">QueueBrowser</a> with ActiveMQ Artemis.<br />
Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.<br />
- A QueueBrowser is used to look at messages on the queue without removing them.
+ 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.</p>
<p>
- The example will send 2 messages on a queue, use a QueueBrowser to browse
+ The example will send 2 messages on a queue, use a QueueBrowser to browse
the queue (looking at the message without removing them) and finally consume the 2 messages
</p>
- <h2>Example step-by-step</h2>
- <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p>
-
- <ol>
- <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
- <pre class="prettyprint">
- <code>InitialContext initialContext = getContext();</code>
- </pre>
-
- <li>We look up the JMS queue object from JNDI</li>
- <pre class="prettyprint">
- <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code>
- </pre>
-
- <li>We look up the JMS connection factory object from JNDI</li>
- <pre class="prettyprint">
- <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li>We create a JMS connection</li>
- <pre class="prettyprint">
- <code>connection = cf.createConnection();</code>
- </pre>
-
- <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
- <pre class="prettyprint">
- <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
- </pre>
-
- <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
- <pre class="prettyprint">
- <code>MessageProducer messageProducer = session.createProducer(topic);</code>
- </pre>
-
- <li>We create 2 JMS text messages that we are going to send.</li>
- <pre class="prettyprint">
- <code> TextMessage message_1 = session.createTextMessage("this is the 1st message");
- TextMessage message_2 = session.createTextMessage("this is the 2nd message");</code>
- </pre>
-
- <li>We send messages to the queue</li>
- <pre class="prettyprint">
- <code>messageProducer.send(message_1);
- messageProducer.send(message_2);</code>
- </pre>
-
- <li>We create a JMS QueueBrowser.<br />
- We have not specified a message selector so the browser will enumerate the entire content of the queue.
- </li>
- <pre class="prettyprint">
- <code>QueueBrowser browser = session.createBrowser(queue);</code>
- </pre>
-
- <li>We browse the queue and display all the messages' text
- </li>
- <pre class="prettyprint">
- <code>Enumeration messageEnum = browser.getEnumeration();
- while (messageEnum.hasMoreElements())
- {
- TextMessage message = (TextMessage)messageEnum.nextElement();
- System.out.println("Browsing: " + message.getText());
- }</code>
- </pre>
-
- <li>We close the browser once we have finished to use it</li>
- <pre class="prettyprint">
- <code>browser.close();</code>
- </pre>
-
- <p>The messages were browsed but they were not removed from the queue. We will now consume them.</p>
-
- <li>We create a JMS Message Consumer to receive the messages.</li>
- <pre class="prettyprint">
- <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
- </pre>
-
- <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
- <pre class="prettyprint">
- <code>connection.start();</code>
- </pre>
-
- <li>The 2 messages arrive at the consumer</li>
- <pre class="prettyprint">
- <code>TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
- System.out.println("Received message: " + messageReceived.getText());
- messageReceived = (TextMessage)messageConsumer.receive(5000);
- System.out.println("Received message: " + messageReceived.getText());</code>
- </pre>
-
- <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre class="prettyprint">
- <code>finally
- {
- if (initialContext != null)
- {
- initialContext.close();
- }
- if (connection != null)
- {
- connection.close();
- }
- }</code>
- </pre>
-
-
-
- </ol>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java
----------------------------------------------------------------------
diff --git a/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java b/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java
index 6c93cc6..d7f060c 100644
--- a/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java
+++ b/examples/jms/browser/src/main/java/org/apache/activemq/artemis/jms/example/QueueBrowserExample.java
@@ -45,8 +45,11 @@ public class QueueBrowserExample
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
// Step 3. Perform a lookup on the Connection Factory
+ // you could alternatively instantiate the connection directly
+ // ConnectionFactory cf = new ActiveMQConnectionFactory(); // this would accept the broker URI as well
ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("ConnectionFactory");
+
// Step 4. Create a JMS Connection
connection = cf.createConnection();
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/client-kickoff/pom.xml
----------------------------------------------------------------------
diff --git a/examples/jms/client-kickoff/pom.xml b/examples/jms/client-kickoff/pom.xml
index 1c86b5a..a07eb35 100644
--- a/examples/jms/client-kickoff/pom.xml
+++ b/examples/jms/client-kickoff/pom.xml
@@ -18,7 +18,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
- <artifactId>artemis-jms-client-kickoff-example</artifactId>
+ <artifactId>client-kickoff</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Kick Off Example</name>
@@ -38,79 +39,84 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
- <artifactId>artemis-core-client</artifactId>
+ <artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jms_2.0_spec</artifactId>
- </dependency>
</dependencies>
<profiles>
<profile>
- <id>example</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <!-- options used for JMX on the example -->
- <javaOptions>-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false</javaOptions>
- </configuration>
- </execution>
- <execution>
- <id>start</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <spawn>true</spawn>
- <testURI>tcp://localhost:61616</testURI>
- <args>
- <param>run</param>
- </args>
- </configuration>
- </execution>
- <execution>
- <id>runClient</id>
- <goals>
- <goal>runClient</goal>
- </goals>
- <configuration>
- <clientClass>org.apache.activemq.artemis.jms.example.ClientKickoffExample</clientClass>
- </configuration>
- </execution>
- <execution>
- <id>stop</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.apache.activemq.examples.jms</groupId>
- <artifactId>artemis-jms-client-kickoff-example</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
+ <!-- specify -PnoServer if you don't want to start the server -->
+ <id>noServer</id>
+ <properties>
+ <noServer>true</noServer>
+ </properties>
</profile>
</profiles>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <!-- options used for JMX on the example -->
+ <javaOptions>-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3000
+ -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
+ </javaOptions>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <spawn>true</spawn>
+ <testURI>tcp://localhost:61616</testURI>
+ <args>
+ <param>run</param>
+ </args>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runClient</id>
+ <goals>
+ <goal>runClient</goal>
+ </goals>
+ <configuration>
+ <clientClass>org.apache.activemq.artemis.jms.example.ClientKickoffExample</clientClass>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <args>
+ <param>stop</param>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq.examples.jms</groupId>
+ <artifactId>client-kickoff</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/client-kickoff/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/client-kickoff/readme.html b/examples/jms/client-kickoff/readme.html
index f30598a..064f7fb 100644
--- a/examples/jms/client-kickoff/readme.html
+++ b/examples/jms/client-kickoff/readme.html
@@ -27,6 +27,8 @@ under the License.
<body onload="prettyPrint()">
<h1>Client Kickoff Example</h1>
+ <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
+
<p>This example shows how to kick off a client connected to ActiveMQ
using <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/">JMX</a></p>
@@ -48,109 +50,5 @@ under the License.
(please note that for this example, we will disable user authentication for simplicity).</p>
<p>With these properties, ActiveMQ Artemis server will be manageable remotely using standard JMX URL on port <code>3000</code>.</p>
</p>
-
- <h2>Example step-by-step</h2>
- <p><em>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</em></p>
- <ol>
- <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from <a href="src/main/resources/activemq/server0/client-jndi.properties">client-jndi.properties</a></li>
- <pre class="prettyprint">
- <code>InitialContext initialContext = getContext(0);</code>
- </pre>
-
- <li>We look up the JMS connection factory object from JNDI</li>
- <pre class="prettyprint">
- <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li>We create a JMS connection</li>
- <pre class="prettyprint">
- <code>connection = cf.createConnection();</code>
- </pre>
-
- <li>We set a <code>ExceptionListener</code> on the connection to be notified after a problem occurred</li>
- <pre class="prettyprint">
- <code>final AtomicReference<JMSException> exception = new AtomicReference<JMSException>();
- connection.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException e)
- {
- exception.set(e);
- }
- });</code>
- </pre>
-
- <li>We start the connection</li>
- <pre class="prettyprint">
- <code>connection.start();</code>
- </pre>
-
- <li>We create a MBean proxy to the ActiveMQServerControlMBean used to manage ActiveMQ Artemis server
- (see <a href="../jmx/readme.html">JMX example</a> for a complete explanation of the different steps)</li>
- <pre class="prettyprint">
- <code>ObjectName on = ObjectNameBuilder.DEFAULT.getActiveMQServerObjectName();
- JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap<String, String>());
- MBeanServerConnection mbsc = connector.getMBeanServerConnection();
- ActiveMQServerControlMBean serverControl = (ActiveMQServerControlMBean)MBeanServerInvocationHandler.newProxyInstance(mbsc,
- on,
- ActiveMQServerControlMBean.class,
- false);
- </code>
- </pre>
-
- <li>Using the server MBean, we list the remote address connected to the server</li>
- <pre class="prettyprint">
- <code>String[] remoteAddresses = serverControl.listRemoteAddresses();
- for (String remoteAddress : remoteAddresses)
- {
- System.out.println(remoteAddress);
- }
- </code>
- </pre>
-
- <p>It will display a single address corresponding to the connection opened at step 3.</p>
-
- <li>We close the connections corresponding to this remote address</li>
- <pre class="prettyprint">
- <code>serverControl.closeConnectionsForAddress(remoteAddresses[0]);</code>
- </pre>
-
- <p>Warnings be displayed on the server output:</p>
- <pre class="prettyprint">
- <code>org.apache.activemq.artemis.jms.example.SpawnedJMSServer out:11:22:33,034 WARN @RMI TCP Connection(3)-192.168.0.10 [RemotingConnectionImpl] Connection failure has been detected connections for /192.168.0.10:52707 closed by management:0
- org.apache.activemq.artemis.jms.example.SpawnedJMSServer out:11:22:33,035 WARN @RMI TCP Connection(3)-192.168.0.10 [ServerSessionImpl] Client connection failed, clearing up resources for session 4646da35-2fe8-11de-9ce9-752ccc2b26e4
- org.apache.activemq.artemis.jms.example.SpawnedJMSServer out:11:22:33,035 WARN @RMI TCP Connection(3)-192.168.0.10 [ServerSessionImpl] Cleared up resources for session 4646da35-2fe8-11de-9ce9-752ccc2b26e4
- </code>
- </pre>
-
- <li>We display the exception received by the connection's ExceptionListener</li>
- <pre class="prettyprint">
- <code>exception.get().printStackTrace();</code>
- </pre>
-
- <p>When the connection was closed on the server-side by the call to <code>serverControl.closeConnectionsForAddress()</code>,
- the client's connection was disconnected and its exception listener was notified.</p>
-
- <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre class="prettyprint">
- <code>finally
- {
- if (initialContext != null)
- {
- initialContext.close();
- }
- if (connection != null)
- {
- connection.close();
- }
- }</code>
- </pre>
- </ol>
-
- <h2>More information</h2>
-
- <ul>
- <li><a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html">Java 5 Management guide</a></li>
- </ul>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/client-side-failoverlistener/pom.xml
----------------------------------------------------------------------
diff --git a/examples/jms/client-side-failoverlistener/pom.xml b/examples/jms/client-side-failoverlistener/pom.xml
index cfdcdd6..4f5eaa5 100644
--- a/examples/jms/client-side-failoverlistener/pom.xml
+++ b/examples/jms/client-side-failoverlistener/pom.xml
@@ -18,7 +18,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
- <artifactId>artemis-jms-client-side-fileoverlistener-example</artifactId>
+ <artifactId>client-side-fileoverlistener</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Client Side Failover listener Example</name>
@@ -46,72 +47,63 @@ under the License.
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jms_2.0_spec</artifactId>
- </dependency>
</dependencies>
- <profiles>
- <profile>
- <id>example</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create0</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server0</instance>
- <dataFolder>../shared</dataFolder>
- <sharedStore>true</sharedStore>
- <slave>false</slave>
- <failoverOnShutdown>true</failoverOnShutdown>
- </configuration>
- </execution>
- <execution>
- <id>create1</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server1</instance>
- <dataFolder>../shared</dataFolder>
- <sharedStore>true</sharedStore>
- <slave>true</slave>
- <portOffset>1</portOffset>
- </configuration>
- </execution>
- <execution>
- <id>runClient</id>
- <goals>
- <goal>runClient</goal>
- </goals>
- <configuration>
- <clientClass>org.apache.activemq.artemis.jms.example.ClientSideFailoverListerExample</clientClass>
- <args>
- <param>${basedir}/target/server0</param>
- <param>${basedir}/target/server1</param>
- </args>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.apache.activemq.examples.jms</groupId>
- <artifactId>artemis-jms-client-side-fileoverlistener-example</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create0</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <instance>${basedir}/target/server0</instance>
+ <dataFolder>../shared</dataFolder>
+ <sharedStore>true</sharedStore>
+ <slave>false</slave>
+ <failoverOnShutdown>true</failoverOnShutdown>
+ </configuration>
+ </execution>
+ <execution>
+ <id>create1</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <instance>${basedir}/target/server1</instance>
+ <dataFolder>../shared</dataFolder>
+ <sharedStore>true</sharedStore>
+ <slave>true</slave>
+ <portOffset>1</portOffset>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runClient</id>
+ <goals>
+ <goal>runClient</goal>
+ </goals>
+ <configuration>
+ <clientClass>org.apache.activemq.artemis.jms.example.ClientSideFailoverListerExample</clientClass>
+ <args>
+ <param>${basedir}/target/server0</param>
+ <param>${basedir}/target/server1</param>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq.examples.jms</groupId>
+ <artifactId>client-side-fileoverlistener</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/client-side-failoverlistener/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/client-side-failoverlistener/readme.html b/examples/jms/client-side-failoverlistener/readme.html
index c58abc6..9f71893 100644
--- a/examples/jms/client-side-failoverlistener/readme.html
+++ b/examples/jms/client-side-failoverlistener/readme.html
@@ -26,88 +26,12 @@ under the License.
</head>
<body onload="prettyPrint()">
<h1>Client Side Kickoff Example</h1>
+ <pre>To run the example, simply type <b>mvn verify</b> from this directory. This example will always spawn and stop multiple servers.</pre>
<p>This example demonstrates how you can listen on failover event on the client side.</p>
<p>In this example there are two nodes running in a cluster, both server will be running for start,
but after a while the first server will crash. This will trigger a fail-over event.</p>
-
- <h2>Example step-by-step</h2>
- <p><em>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</em></p>
- <ol>
- <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from <a href="src/main/resources/activemq/server0/client-jndi.properties">client-jndi.properties</a></li>
- <pre class="prettyprint">
- <code>InitialContext initialContext = getContext(0);</code>
- </pre>
- <li>We look up the JMS Queue object from JNDI</li>
- <pre class="prettyprint">
- <code>Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");</code>
- </pre>
-
- <li>We look up a JMS Connection Factory object from JNDI on server 0</li>
- <pre class="prettyprint">
- <code>ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li>We create a JMS connection from the same connection factory, wait a little while to make sure broadcasts from all nodes have reached the client</li>
- <pre class="prettyprint">
- <code>
- Thread.sleep(5000);
- connectionA = connectionFactory.createConnection();
- ((ActiveMQConnection)connectionA).setFailoverListener(new FailoverListenerImpl());
- </code>
- </pre>
-
- <li>We create JMS Sessions</li>
- <pre class="prettyprint">
- <code>Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
- </pre>
-
- <li>We create JMS MessageProducer objects on the sessions</li>
- <pre class="prettyprint">
- <code>MessageProducer producerA = sessionA.createProducer(queue);</code>
- </pre>
-
- <li>We send some messages on each producer</li>
- <pre class="prettyprint">
- <code>
- final int numMessages = 10;
-
- for (int i = 0; i < numMessages; i++)
- {
- TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i);
- producerA.send(messageA);
- System.out.println("Sent message: " + messageA.getText());
- }
- </code>
- </pre>
-
- <li>We start the connection to consume messages</li>
- <pre class="prettyprint">
- <code>connectionA.start();</code>
- </pre>
-
- <li>We consume messages from the session A, one at a time. We reached message no 5 the first server will crash</li>
- <pre class="prettyprint">
- <code>consume(sessionA, queue, numMessages, "A");</code>
- </pre>
-
- <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre class="prettyprint">
- <code>
- if (connectionA != null)
- {
- connectionA.close();
- }
-
- if (initialContext != null)
- {
- initialContext.close();
- }
- </code>
- </pre>
- </ol>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/client-side-load-balancing/pom.xml
----------------------------------------------------------------------
diff --git a/examples/jms/client-side-load-balancing/pom.xml b/examples/jms/client-side-load-balancing/pom.xml
index 77c8186..40fed73 100644
--- a/examples/jms/client-side-load-balancing/pom.xml
+++ b/examples/jms/client-side-load-balancing/pom.xml
@@ -18,7 +18,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
<version>1.0.1-SNAPSHOT</version>
</parent>
- <artifactId>artemis-jms-client-side-load-balancing-example</artifactId>
+ <artifactId>client-side-load-balancing</artifactId>
<packaging>jar</packaging>
<name>ActiveMQ Artemis JMS Client Side Load Balancing Example</name>
@@ -41,155 +42,164 @@ under the License.
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jms_2.0_spec</artifactId>
- </dependency>
</dependencies>
<profiles>
<profile>
- <id>example</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.activemq</groupId>
- <artifactId>artemis-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create0</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server0</instance>
- <clustered>true</clustered>
- </configuration>
- </execution>
- <execution>
- <id>create1</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server1</instance>
- <clustered>true</clustered>
- <portOffset>1</portOffset>
- </configuration>
- </execution>
- <execution>
- <id>create2</id>
- <goals>
- <goal>create</goal>
- </goals>
- <configuration>
- <instance>${basedir}/target/server2</instance>
- <clustered>true</clustered>
- <portOffset>2</portOffset>
- </configuration>
- </execution>
- <execution>
- <id>start0</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <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>start1</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <spawn>true</spawn>
- <location>${basedir}/target/server1</location>
- <testURI>tcp://localhost:61617</testURI>
- <args>
- <param>run</param>
- </args>
- <name>server1</name>
- </configuration>
- </execution>
- <execution>
- <id>start2</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <spawn>true</spawn>
- <location>${basedir}/target/server2</location>
- <testURI>tcp://localhost:61618</testURI>
- <args>
- <param>run</param>
- </args>
- <name>server2</name>
- </configuration>
- </execution>
- <execution>
- <id>runClient</id>
- <goals>
- <goal>runClient</goal>
- </goals>
- <configuration>
- <clientClass>org.apache.activemq.artemis.jms.example.ClientSideLoadBalancingExample</clientClass>
- </configuration>
- </execution>
- <execution>
- <id>stop0</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <location>${basedir}/target/server0</location>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- <execution>
- <id>stop1</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <location>${basedir}/target/server1</location>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- <execution>
- <id>stop2</id>
- <goals>
- <goal>cli</goal>
- </goals>
- <configuration>
- <location>${basedir}/target/server2</location>
- <args>
- <param>stop</param>
- </args>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.apache.activemq.examples.jms</groupId>
- <artifactId>artemis-jms-client-side-load-balancing-example</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
+ <!-- specify -PnoServer if you don't want to start the server -->
+ <id>noServer</id>
+ <properties>
+ <noServer>true</noServer>
+ </properties>
</profile>
</profiles>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>artemis-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create0</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <instance>${basedir}/target/server0</instance>
+ <clustered>true</clustered>
+ </configuration>
+ </execution>
+ <execution>
+ <id>create1</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <instance>${basedir}/target/server1</instance>
+ <clustered>true</clustered>
+ <portOffset>1</portOffset>
+ </configuration>
+ </execution>
+ <execution>
+ <id>create2</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <instance>${basedir}/target/server2</instance>
+ <clustered>true</clustered>
+ <portOffset>2</portOffset>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start0</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <spawn>true</spawn>
+ <ignore>${noServer}</ignore>
+ <location>${basedir}/target/server0</location>
+ <testURI>tcp://localhost:61616</testURI>
+ <args>
+ <param>run</param>
+ </args>
+ <name>server0</name>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start1</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <spawn>true</spawn>
+ <location>${basedir}/target/server1</location>
+ <testURI>tcp://localhost:61617</testURI>
+ <args>
+ <param>run</param>
+ </args>
+ <name>server1</name>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start2</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <spawn>true</spawn>
+ <location>${basedir}/target/server2</location>
+ <testURI>tcp://localhost:61618</testURI>
+ <args>
+ <param>run</param>
+ </args>
+ <name>server2</name>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runClient</id>
+ <goals>
+ <goal>runClient</goal>
+ </goals>
+ <configuration>
+ <clientClass>org.apache.activemq.artemis.jms.example.ClientSideLoadBalancingExample</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>
+ <execution>
+ <id>stop1</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <location>${basedir}/target/server1</location>
+ <args>
+ <param>stop</param>
+ </args>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop2</id>
+ <goals>
+ <goal>cli</goal>
+ </goals>
+ <configuration>
+ <ignore>${noServer}</ignore>
+ <location>${basedir}/target/server2</location>
+ <args>
+ <param>stop</param>
+ </args>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.activemq.examples.jms</groupId>
+ <artifactId>client-side-load-balancing</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/client-side-load-balancing/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/client-side-load-balancing/readme.html b/examples/jms/client-side-load-balancing/readme.html
index 7cfc684..dc06623 100644
--- a/examples/jms/client-side-load-balancing/readme.html
+++ b/examples/jms/client-side-load-balancing/readme.html
@@ -26,6 +26,7 @@ under the License.
</head>
<body onload="prettyPrint()">
<h1>JMS Client-Side Load-Balancing Example</h1>
+ <pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
<p>This example demonstrates how connnections created from a single JMS Connection factory can be created
to different nodes of the cluster. In other words it demonstrates how ActiveMQ Artemis does <b>client side load balancing</b> of
@@ -40,129 +41,9 @@ under the License.
<p>This example starts three servers which all broadcast their location using UDP discovery. The UDP broadcast configuration
can be seen in the <code>broker.xml</code> file.</p>
<p>A JMS ConnectionFactory is deployed on each server specifying the discovery group that will be used by that
- connection factory.</p>
+ connection factory.</p>
<p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering
- section of the user manual.</p>
+ section of the user manual.</p>
- <h2>Example step-by-step</h2>
- <p><i>To run the example, simply type <code>mvn verify -Pexample</code> from this directory</i></p>
-
- <ol>
- <li> Get an initial context for looking up JNDI from server 0.</li>
- <pre class="prettyprint">
- <code>initialContext = getContext(0);</code>
- </pre>
-
- <li>Look-up the JMS Queue object from JNDI</li>
- <pre class="prettyprint">
- <code>Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");</code>
- </pre>
-
- <li>Look-up a JMS Connection Factory object from JNDI on server 0</li>
- <pre class="prettyprint">
- <code>ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li> We create 3 JMS connections from the same connection factory. Since we are using round-robin
- load-balancing this should result in each sessions being connected to a different node of the cluster</li>
- <pre class="prettyprint">
- <code>
- Connection conn = connectionFactory.createConnection();
- connectionA = connectionFactory.createConnection();
- connectionB = connectionFactory.createConnection();
- connectionC = connectionFactory.createConnection();
- conn.close();
- </code>
- </pre>
-
- <li>We create JMS Sessions</li>
- <pre class="prettyprint">
- <code>
- Session sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Session sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Session sessionC = connectionC.createSession(false, Session.AUTO_ACKNOWLEDGE);
- </code>
- </pre>
-
- <li>We create JMS MessageProducer objects on the sessions</li>
- <pre class="prettyprint">
- <code>
- MessageProducer producerA = sessionA.createProducer(queue);
- MessageProducer producerB = sessionB.createProducer(queue);
- MessageProducer producerC = sessionC.createProducer(queue);
- </code>
- </pre>
-
- <li>We send some messages on each producer</li>
- <pre class="prettyprint">
- <code>
- final int numMessages = 10;
-
- for (int i = 0; i < numMessages; i++)
- {
- TextMessage messageA = sessionA.createTextMessage("A:This is text message " + i);
- producerA.send(messageA);
- System.out.println("Sent message: " + messageA.getText());
-
- TextMessage messageB = sessionB.createTextMessage("B:This is text message " + i);
- producerB.send(messageB);
- System.out.println("Sent message: " + messageB.getText());
-
- TextMessage messageC = sessionC.createTextMessage("C:This is text message " + i);
- producerC.send(messageC);
- System.out.println("Sent message: " + messageC.getText());
- }
- </code>
- </pre>
-
- <li>We start the connection to consume messages</li>
- <pre class="prettyprint">
- <code>
- connectionA.start();
- connectionB.start();
- connectionC.start();
- </code>
- </pre>
-
- <li>We consume messages from the 3 session, one at a time.<br>
- We try to consume one more message than expected from each session. If
- the session were not properly load-balanced, we would be missing a
- message from one of the sessions at the end.</li>
- <pre class="prettyprint">
- <code>
- consume(sessionA, queue, numMessages, "A");
- consume(sessionB, queue, numMessages, "B");
- consume(sessionC, queue, numMessages, "C");
- </code>
- </pre>
-
- <li>And finally (no pun intended), <b>always</b> remember to close your JMS resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre class="prettyprint">
- <code>
- finally
- {
- if (connectionA != null)
- {
- connectionA.close();
- }
- if (connectionB != null)
- {
- connectionB.close();
- }
- if (connectionC != null)
- {
- connectionC.close();
- }
-
- if (initialContext != null)
- {
- initialContext.close();
- }
- }
- </code>
- </pre>
-
- </ol>
- </body>
+ </body>
</html>