http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-durable-subscription/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-durable-subscription/pom.xml b/examples/jms/clustered-durable-subscription/pom.xml index 041fbe3..5b678d2 100644 --- a/examples/jms/clustered-durable-subscription/pom.xml +++ b/examples/jms/clustered-durable-subscription/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-clustered-durable-subscription-example</artifactId> + <artifactId>clustered-durable-subscription</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Clustered Durable Subscription Example</name> @@ -37,116 +38,130 @@ 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>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.ClusteredDurableSubscriptionExample</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-clustered-durable-subscription-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> + <clustered>true</clustered> + <instance>${basedir}/target/server0</instance> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <clustered>true</clustered> + <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.ClusteredDurableSubscriptionExample + </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>clustered-durable-subscription</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/clustered-durable-subscription/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-durable-subscription/readme.html b/examples/jms/clustered-durable-subscription/readme.html index 0d17214..57597bd 100644 --- a/examples/jms/clustered-durable-subscription/readme.html +++ b/examples/jms/clustered-durable-subscription/readme.html @@ -27,6 +27,8 @@ under the License. <body onload="prettyPrint()"> <h1>JMS Durable Subscription 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 clustered JMS durable subscription. Normally durable subscriptions exist on a single node and can only have one subscriber at any one time, however, with ActiveMQ Artemis it's possible to create durable subscription instances with the same name and client-id @@ -45,6 +47,7 @@ under the License. JNDI, these could be instantiated directly. <p>Here's the relevant snippet from the server configuration, which tells the server to form a cluster between the two nodes and to load balance the messages between the nodes.</p> + <p>The cli create method will define this section by default if you use --clustered as a parameter</p> <pre class="prettyprint"> <code><cluster-connection name="my-cluster"> <address>jms</address> @@ -59,155 +62,5 @@ under the License. <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering 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> - ic0 = getContext(0); - </code> - </pre> - - <li>Look-up the JMS Topic object from JNDI</li> - <pre class="prettyprint"> - <code>Topic topic = (Topic)ic0.lookup("/topic/exampleTopic");</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 0</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code> - </pre> - - <li>Get an initial context for looking up JNDI from server 1.</li> - <pre class="prettyprint"> - <code>ic1 = getContext(1);</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 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 - and set the same client-id.</li> - <pre class="prettyprint"> - <code> - connection0 = cf0.createConnection(); - final String clientID = "my-client-id"; - connection0.setClientID(clientID); - </code> - </pre> - - <li>We create a JMS Connection connection1 which is a connection to server 1 - and set the same client-id.</li> - <pre class="prettyprint"> - <code> - connection1 = cf1.createConnection(); - connection1.setClientID(clientID); - </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 connections to ensure delivery occurs on them</li> - <pre class="prettyprint"> - <code> - connection0.start(); - - connection1.start(); - </code> - </pre> - - <li>We create JMS durable subscriptions with the same name and client-id on both nodes - of the cluster - </li> - <pre class="prettyprint"> - <code> - final String subscriptionName = "my-subscription"; - - MessageConsumer subscriber0 = session0.createDurableSubscriber(topic, subscriptionName); - - MessageConsumer subscriber1 = session1.createDurableSubscriber(topic, subscriptionName); - </code> - </pre> - - <li>We create a JMS MessageProducer object on server 0.</li> - <pre class="prettyprint"> - <code> - MessageProducer producer = session0.createProducer(topic);</code> - </pre> - - <li>We send some messages to server 0.</li> - <pre class="prettyprint"> - <code> - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("This is text message " + i); - - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - } - </code> - </pre> - - <li> - We now consume those messages on *both* server 0 and server 1. - Note that the messages have been load-balanced between the two nodes, with some - messages on node 0 and others on node 1. - The "logical" subscription is distributed across the cluster and contains exactly one copy of all the messages sent. - </li> - <pre class="prettyprint"> - <code> - for (int i = 0; i < numMessages; i += 2) - { - TextMessage message0 = (TextMessage)consumer0.receive(5000); - - System.out.println("Got message: " + message0.getText() + " from node 0"); - - TextMessage message1 = (TextMessage)consumer1.receive(5000); - - System.out.println("Got message: " + message1.getText() + " from node 1"); - } - </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(); - } - } - </code> - </pre> - - </ol> - </body> + </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java b/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java index 31d1434..2dceb7c 100644 --- a/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java +++ b/examples/jms/clustered-durable-subscription/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredDurableSubscriptionExample.java @@ -26,6 +26,8 @@ import javax.jms.Topic; import javax.naming.InitialContext; import java.util.Hashtable; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; + /** * A simple example that shows a JMS Durable Subscription across two nodes of a cluster. * @@ -40,36 +42,15 @@ public class ClusteredDurableSubscriptionExample Connection connection1 = null; - InitialContext ic0 = null; - - InitialContext ic1 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 0 - 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://localhost:61616"); - properties.put("topic.topic/exampleTopic", "exampleTopic"); - ic0 = new InitialContext(properties); - - // Step 2. Look-up the JMS Topic object from JNDI - Topic topic = (Topic)ic0.lookup("topic/exampleTopic"); - - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 1 - - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); + // Step 1. Instantiate the connection factory on server 0 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); + // Step 2. nstantiate the connection factory on server 1 + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); - // Step 6. We create a JMS Connection connection0 which is a connection to server 0 + // Step 3. We create a JMS Connection connection0 which is a connection to server 0 // and set the client-id connection0 = cf0.createConnection(); @@ -77,38 +58,41 @@ public class ClusteredDurableSubscriptionExample connection0.setClientID(clientID); - // Step 7. We create a JMS Connection connection1 which is a connection to server 1 + // Step 4. We create a JMS Connection connection1 which is a connection to server 1 // and set the same client-id connection1 = cf1.createConnection(); connection1.setClientID(clientID); - // Step 8. We create a JMS Session on server 0 + // Step 5. We create a JMS Session on server 0 Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 9. We create a JMS Session on server 1 + // Step 6. We create a JMS Session on server 1 Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 10. We start the connections to ensure delivery occurs on them + // Step 7. We start the connections to ensure delivery occurs on them connection0.start(); connection1.start(); - // Step 11. We create JMS durable subscriptions with the same name and client-id on both nodes + // Step 8. We create JMS durable subscriptions with the same name and client-id on both nodes // of the cluster final String subscriptionName = "my-subscription"; + // Step 9. lookup the topic + Topic topic = session0.createTopic("exampleTopic"); + MessageConsumer subscriber0 = session0.createDurableSubscriber(topic, subscriptionName); MessageConsumer subscriber1 = session1.createDurableSubscriber(topic, subscriptionName); Thread.sleep(1000); - // Step 12. We create a JMS MessageProducer object on server 0 + // Step 10. We create a JMS MessageProducer object on server 0 MessageProducer producer = session0.createProducer(topic); - // Step 13. We send some messages to server 0 + // Step 11. We send some messages to server 0 final int numMessages = 10; @@ -121,7 +105,7 @@ public class ClusteredDurableSubscriptionExample System.out.println("Sent message: " + message.getText()); } - // Step 14. We now consume those messages on *both* server 0 and server 1. + // Step 12. We now consume those messages on *both* server 0 and server 1. // Note that the messages have been load-balanced between the two nodes, with some // messages on node 0 and others on node 1. // The "logical" subscription is distributed across the cluster and contains exactly one copy of all the @@ -150,16 +134,6 @@ public class ClusteredDurableSubscriptionExample { connection1.close(); } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } } } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml index 6214a63..2bfaeae 100644 --- a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml index 3d1cb2e..8134f27 100644 --- a/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-durable-subscription/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> <connectors> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-grouping/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-grouping/pom.xml b/examples/jms/clustered-grouping/pom.xml index 0f9f101..86338f3 100644 --- a/examples/jms/clustered-grouping/pom.xml +++ b/examples/jms/clustered-grouping/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-clustered-grouping-example</artifactId> + <artifactId>clustered-grouping</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS CLustered Grouping Example</name> @@ -37,152 +38,166 @@ 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>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> - </configuration> - </execution> - <execution> - <id>create2</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server2</instance> - <configuration>${basedir}/target/classes/activemq/server2</configuration> - </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.ClusteredGroupingExample</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-clustered-grouping-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> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</configuration> + </configuration> + </execution> + <execution> + <id>create2</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server2</instance> + <configuration>${basedir}/target/classes/activemq/server2</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>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.ClusteredGroupingExample</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>clustered-grouping</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/clustered-grouping/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-grouping/readme.html b/examples/jms/clustered-grouping/readme.html index 1f5010c..c605168 100644 --- a/examples/jms/clustered-grouping/readme.html +++ b/examples/jms/clustered-grouping/readme.html @@ -25,6 +25,8 @@ under the License. <body> <h1>JMS Clustered Grouping 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 to ensure strict ordering across a cluster using clustered message grouping</p> <p>We create 3 nodes each with a grouping message handler, one with a Local handler and 2 with a Remote handler.</p> <p>The local handler acts as an arbitrator for the 2 remote handlers, holding the information on routes and communicating @@ -75,191 +77,5 @@ under the License. </code> </pre> - <p>For more information on ActiveMQ Artemis clustering and grouping see the clustering and grouping - 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>ic0 = getContext(0);</code> - </pre> - - <li>Look-up the JMS Queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 0</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code> - </pre> - - <li>Get an initial context for looking up JNDI from server 1.</li> - <pre class="prettyprint"> - <code>ic1 = getContext(1);</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 1</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory"); - </code> - </pre> - - <li>Get an initial context for looking up JNDI from server 2.</li> - <pre class="prettyprint"> - <code>ic2 = getContext(2);</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 2</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf2 = (ConnectionFactory)ic2.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 connection0 which is a connection to server 1</li> - <pre class="prettyprint"> - <code>connection1 = cf1.createConnection();</code> - </pre> - - <li>We create a JMS Connection connection0 which is a connection to server 2</li> - <pre class="prettyprint"> - <code>connection2 = cf2.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 create a JMS Session on server 2</li> - <pre class="prettyprint"> - <code>Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);</code> - </pre> - - <li>We start the connections to ensure delivery occurs on them</li> - <pre class="prettyprint"> - <code> - connection0.start(); - - connection1.start(); - - connection2.start();</code> - </pre> - - <li>We create JMS MessageConsumer objects on server 0</li> - <pre class="prettyprint"> - <code>MessageConsumer consumer = session0.createConsumer(queue);</code> - </pre> - - <li>We create a JMS MessageProducer object on server 0, 1 and 2</li> - <pre class="prettyprint"> - <code> - MessageProducer producer0 = session0.createProducer(queue); - - MessageProducer producer1 = session1.createProducer(queue); - - MessageProducer producer2 = session2.createProducer(queue);</code> - </pre> - - <li>We send some messages to server 0, 1 and 2 with the same groupid set</li> - <pre class="prettyprint"> - <code> - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("This is text message " + i); - - message.setStringProperty(ActiveMQMessage.JMSXGROUPID, "Group-0"); - - producer0.send(message); - - System.out.println("Sent messages: " + message.getText() + " to node 0"); - } - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session1.createTextMessage("This is text message " + (i + 10)); - - message.setStringProperty(ActiveMQMessage.JMSXGROUPID, "Group-0"); - - producer1.send(message); - - System.out.println("Sent messages: " + message.getText() + " to node 1"); - - } - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session2.createTextMessage("This is text message " + (i + 20)); - - message.setStringProperty(ActiveMQMessage.JMSXGROUPID, "Group-0"); - - producer2.send(message); - - System.out.println("Sent messages: " + message.getText() + " to node 2"); - } - </code> - </pre> - - <li>We now consume those messages from server 0. We note the messages have all been sent to the same consumer on the same node</li> - <pre class="prettyprint"> - <code> - for (int i = 0; i < numMessages * 3; i++) - { - TextMessage message0 = (TextMessage)consumer.receive(5000); - - System.out.println("Got message: " + message0.getText() + " from node 0"); - - } - </code> - </pre> - <li>Finally, Be sure to close our resources!</li> - <pre class="prettyprint"> - <code> - if (connection0 != null) - { - connection0.close(); - } - - if (connection1 != null) - { - connection1.close(); - } - - if (connection2 != null) - { - connection2.close(); - } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } - - if (ic2 != null) - { - ic2.close(); - }</code> - </pre> - - </ol> - </body> + </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java b/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java index a60ea6b..04fec83 100644 --- a/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java +++ b/examples/jms/clustered-grouping/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredGroupingExample.java @@ -23,8 +23,10 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import javax.naming.InitialContext; -import java.util.Hashtable; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQQueue; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -40,82 +42,58 @@ public class ClusteredGroupingExample Connection connection2 = null; - InitialContext ic0 = null; + try + { + // Step 1. We will instantiate the queue object directly on this example + // This could be done through JNDI or JMSession.createQueue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - InitialContext ic1 = null; + // Step 2. create a connection factory towards server 0. + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616"); - InitialContext ic2 = null; + // Step 3. create a connection factory towards server 1. + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); - try - { - // Step 1. Get an initial context for looking up JNDI from server 0 - 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://localhost:61616"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); - - // Step 2. Look-up the JMS Queue object from JNDI - Queue queue = (Queue)ic0.lookup("queue/exampleQueue"); - - // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0 - ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 1 - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - ic1 = new InitialContext(properties); - - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1 - ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory"); - - // Step 4. Get an initial context for looking up JNDI from server 2 - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61618"); - ic2 = new InitialContext(properties); - - // Step 5. Look-up a JMS Connection Factory object from JNDI on server 2 - ConnectionFactory cf2 = (ConnectionFactory)ic2.lookup("ConnectionFactory"); - - // Step 6. We create a JMS Connection connection0 which is a connection to server 0 + // Step 4. create a connection factory towards server 2. + ConnectionFactory cf2 = new ActiveMQConnectionFactory("tcp://localhost:61618"); + + // Step 5. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); - // Step 7. We create a JMS Connection connection1 which is a connection to server 1 + // Step 6. We create a JMS Connection connection1 which is a connection to server 1 connection1 = cf1.createConnection(); - // Step 8. We create a JMS Connection connection2 which is a connection to server 2 + // Step 7. We create a JMS Connection connection2 which is a connection to server 2 connection2 = cf2.createConnection(); - // Step 9. We create a JMS Session on server 0 + // Step 8. We create a JMS Session on server 0 Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 10. We create a JMS Session on server 1 + // Step 9. We create a JMS Session on server 1 Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 11. We create a JMS Session on server 2 + // Step 10. We create a JMS Session on server 2 Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - // Step 12. We start the connections to ensure delivery occurs on them + // Step 11. We start the connections to ensure delivery occurs on them connection0.start(); connection1.start(); connection2.start(); - // Step 13. We create JMS MessageConsumer objects on server 0 + // Step 12. We create JMS MessageConsumer objects on server 0 MessageConsumer consumer = session0.createConsumer(queue); - // Step 14. We create a JMS MessageProducer object on server 0, 1 and 2 + // Step 13. We create a JMS MessageProducer object on server 0, 1 and 2 MessageProducer producer0 = session0.createProducer(queue); MessageProducer producer1 = session1.createProducer(queue); MessageProducer producer2 = session2.createProducer(queue); - // Step 15. We send some messages to server 0, 1 and 2 with the same groupid set + // Step 14. We send some messages to server 0, 1 and 2 with the same groupid set final int numMessages = 10; @@ -153,7 +131,7 @@ public class ClusteredGroupingExample System.out.println("Sent messages: " + message.getText() + " to node 2"); } - // Step 16. We now consume those messages from server 0 + // Step 15. We now consume those messages from server 0 // We note the messages have all been sent to the same consumer on the same node for (int i = 0; i < numMessages * 3; i++) @@ -182,21 +160,6 @@ public class ClusteredGroupingExample { connection2.close(); } - - if (ic0 != null) - { - ic0.close(); - } - - if (ic1 != null) - { - ic1.close(); - } - - if (ic2 != null) - { - ic2.close(); - } } } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml index 77fa2e6..4520059 100644 --- a/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-grouping/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml index fabd98d..4765f7a 100644 --- a/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-grouping/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml index 07d18fc..16bf2eb 100644 --- a/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/clustered-grouping/src/main/resources/activemq/server2/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-jgroups/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-jgroups/pom.xml b/examples/jms/clustered-jgroups/pom.xml index fc90be7..9930edc 100644 --- a/examples/jms/clustered-jgroups/pom.xml +++ b/examples/jms/clustered-jgroups/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> @@ -37,123 +38,133 @@ 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> - <goals> - <goal>create</goal> - </goals> - <configuration> - <libList> - <!-- You need to add jgroups.jar to the server's lib --> - <arg>org.jgroups:jgroups:3.6.0.Final</arg> - </libList> - <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> - <!-- You need to add jgroups.jar to the server's lib --> - <arg>org.jgroups:jgroups:3.6.0.Final</arg> - </libList> - <instance>${basedir}/target/server1</instance> - <configuration>${basedir}/target/classes/activemq/server1</configuration> - </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.ClusteredJgroupsExample</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>clustered-jgroups</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> + <libList> + <!-- You need to add jgroups.jar to the server's lib --> + <arg>org.jgroups:jgroups:3.6.0.Final</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> + <!-- You need to add jgroups.jar to the server's lib --> + <arg>org.jgroups:jgroups:3.6.0.Final</arg> + </libList> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</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>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.ClusteredJgroupsExample</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> + <location>${basedir}/target/server1</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>clustered-jgroups</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/clustered-jgroups/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-jgroups/readme.html b/examples/jms/clustered-jgroups/readme.html index a88ce0d..123e33a 100644 --- a/examples/jms/clustered-jgroups/readme.html +++ b/examples/jms/clustered-jgroups/readme.html @@ -27,7 +27,9 @@ under the License. <body onload="prettyPrint()"> <h1>ActiveMQ Artemis Clustering with JGroups Example</h1> - <p>This example demonstrates the working of a two node cluster using JGroups as the underlying topology broadcasting/discovery + <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 the working of a two node cluster using JGroups as the underlying topology broadcasting/discovery technique.</p> <p>We deploy a queue on to the cluster, then create a consumer on the queue on each node, and we create a producer on only one of the nodes.</p> <p>We then send some messages via the producer, and we verify that <b>both</b> consumers receive the sent messages @@ -58,150 +60,8 @@ under the License. </discovery-group> </discovery-groups> </code> - </pre> + </pre> <p>For more information on ActiveMQ Artemis clustering in general, please see the clustering - section of the user manual.</p> - <h2>Example step-by-step</h2> - <p><i>To run the example, simply type <code>./build.sh</code> (or <code>build.bat</code> on windows) from this directory</i></p> - - <ol> - <li> Get an initial context for looking up JNDI from server 0.</li> - <pre class="prettyprint"> - <code> - ic0 = getContext(0); - </code> - </pre> - - <li>Look-up the JMS Queue object from JNDI</li> - <pre class="prettyprint"> - <code>Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 0</li> - <pre class="prettyprint"> - <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code> - </pre> - - <li>Get an initial context for looking up JNDI from server 1.</li> - <pre class="prettyprint"> - <code>ic1 = getContext(1);</code> - </pre> - - <li>Look-up a JMS Connection Factory object from JNDI on server 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 connections to ensure delivery occurs on them</li> - <pre class="prettyprint"> - <code> - connection0.start(); - - connection1.start(); - </code> - </pre> - - <li>We create JMS MessageConsumer objects on server 0 and server 1</li> - <pre class="prettyprint"> - <code> - MessageConsumer consumer0 = session0.createConsumer(queue); - - MessageConsumer consumer1 = session1.createConsumer(queue); - </code> - </pre> - - <li>We create a JMS MessageProducer object on server 0.</li> - <pre class="prettyprint"> - <code> - MessageProducer producer = session0.createProducer(queue);</code> - </pre> - - <li>We send some messages to server 0.</li> - <pre class="prettyprint"> - <code> - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("This is text message " + i); - - producer.send(message); - - System.out.println("Sent message: " + message.getText()); - } - </code> - </pre> - - <li>We now consume those messages on *both* server 0 and server 1. - We note the messages have been distributed between servers in a round robin fashion. - ActiveMQ Artemis has <b>load balanced</b> the messages between the available consumers on the different nodes. - ActiveMQ Artemis can be configured to always load balance messages to all nodes, or to only balance messages - to nodes which have consumers with no or matching selectors. See the user manual for more details.</li> - JMS Queues implement point-to-point message where each message is only ever consumed by a - maximum of one consumer. - <pre class="prettyprint"> - <code> - for (int i = 0; i < numMessages; i += 2) - { - TextMessage message0 = (TextMessage)consumer0.receive(5000); - - System.out.println("Got message: " + message0.getText() + " from node 0"); - - TextMessage message1 = (TextMessage)consumer1.receive(5000); - - System.out.println("Got message: " + message1.getText() + " from node 1"); - } - </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(); - } - } - </code> - </pre> - - </ol> + section of the user manual.</p> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml index 4af9867..17809e5 100644 --- a/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-jgroups/src/main/resources/activemq/server0/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml index 3393a42..267eae7 100644 --- a/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-jgroups/src/main/resources/activemq/server1/broker.xml @@ -29,13 +29,13 @@ under the License. <core xmlns="urn:activemq:core"> - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> + <bindings-directory>./data/bindings</bindings-directory> - <journal-directory>${data.dir:./data}/journal</journal-directory> + <journal-directory>./data/journal</journal-directory> - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> + <large-messages-directory>./data/largemessages</large-messages-directory> - <paging-directory>${data.dir:./data}/paging</paging-directory> + <paging-directory>./data/paging</paging-directory> <!-- Connectors --> <connectors> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-queue/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-queue/pom.xml b/examples/jms/clustered-queue/pom.xml index 7b42875..6bd1537 100644 --- a/examples/jms/clustered-queue/pom.xml +++ b/examples/jms/clustered-queue/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> @@ -37,115 +38,126 @@ 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>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> - </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.ClusteredQueueExample</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>clustered-queue</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> + <configuration>${basedir}/target/classes/activemq/server0</configuration> + </configuration> + </execution> + <execution> + <id>create1</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server1</instance> + <configuration>${basedir}/target/classes/activemq/server1</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>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.ClusteredQueueExample</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>clustered-queue</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project>
