http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-queue/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-queue/readme.html b/examples/jms/clustered-queue/readme.html index 60ebd89..d89ed24 100644 --- a/examples/jms/clustered-queue/readme.html +++ b/examples/jms/clustered-queue/readme.html @@ -27,6 +27,8 @@ under the License. <body onload="prettyPrint()"> <h1>JMS Load Balanced Clustered Queue 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 JMS queue deployed on two different nodes. The two nodes are configured to form a cluster.</p> <p>We 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 @@ -50,147 +52,5 @@ under the License. </pre> <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 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> </body> </html>
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java b/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java index 12a0a45..1ee779a 100644 --- a/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.java +++ b/examples/jms/clustered-queue/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredQueueExample.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 @@ -38,33 +40,16 @@ public class ClusteredQueueExample 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("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); + // Step 2. Instantiate the Queue + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // 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); + // Instantiate connection towards 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"); + ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617"); // Step 6. We create a JMS Connection connection0 which is a connection to server 0 connection0 = cf0.createConnection(); @@ -135,16 +120,6 @@ public class ClusteredQueueExample { 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-queue/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml index db97076..eb30a90 100644 --- a/examples/jms/clustered-queue/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-queue/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 --> <connectors> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-standalone/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-standalone/pom.xml b/examples/jms/clustered-standalone/pom.xml deleted file mode 100644 index e37336f..0000000 --- a/examples/jms/clustered-standalone/pom.xml +++ /dev/null @@ -1,188 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>jms-examples</artifactId> - <version>1.0.1-SNAPSHOT</version> - </parent> - - <artifactId>artemis-jms-clustered-standalone-example</artifactId> - <packaging>jar</packaging> - <name>ActiveMQ Artemis JMS Clustered Standalone Example</name> - - <properties> - <activemq.basedir>${project.basedir}/../../..</activemq.basedir> - </properties> - - <dependencies> - <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> - <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.ClusteredStandaloneExample</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-standalone-example</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-standalone/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-standalone/readme.html b/examples/jms/clustered-standalone/readme.html deleted file mode 100644 index b72aa77..0000000 --- a/examples/jms/clustered-standalone/readme.html +++ /dev/null @@ -1,70 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<html> - <head> - <title>JMS Clustered Stand-alone Example</title> - <link rel="stylesheet" type="text/css" href="../common/common.css" /> - <link rel="stylesheet" type="text/css" href="../common/prettify.css" /> - <script type="text/javascript" src="../common/prettify.js"></script> - </head> - <body onload="prettyPrint()"> - <h1>JMS Clustered Stand-alone Example</h1> - - <p>This example demonstrates a JMS Topic deployed on three different nodes. - The three nodes are configured to form a cluster.</p> - <p>Subscribers for the topic are created on each node, and a producer is created on only one of the nodes.</p> - <p>Some messages are sent by the producer, and we verify that <strong>all</strong> subscribers receive all the - sent messages.</p> - <p>This example uses ActiveMQ's default stand-alone clustered configuration. - The relevant snippet from the server configuration, which tells the servers to form a cluster between the three nodes - and to load balance the messages between the nodes is:</p> - <pre class="prettyprint"> - <code><cluster-connection name="my-cluster"> - <address>jms</address> - <discovery-group-ref discovery-group-name="dg-group1"/> - </cluster-connection> - </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>. This will - automatically start the 3 cluster nodes, each with its specific configuration.</p> - <p>To start the tests <em>manually</em>, the following steps are:</p> - <ul> - <li>create 4 terminals (3 for the servers and 1 for the example client)</li> - <li>in the first terminal, go to the <code>bin</code> directory and start the first server (with default configuration): - <pre class="prettyprint"><code>./run.sh ../config/stand-alone/clustered</code></pre> - <li>in the second terminal, start the second server: - <pre class="prettyprint"><code>export CLUSTER_PROPS="-Ddata.dir=../data-server2 -Djnp.port=2099 -Djnp.rmiPort=2098 -Dactivemq.remoting.netty.port=6445 -Dactivemq.remoting.netty.batch.port=6455" -./run.sh ../config/stand-alone/clustered</code></pre> - <li>in the third terminal, start the third server (with default configuration): - <pre class="prettyprint"><code>export CLUSTER_PROPS="-Ddata.dir=../data-server3 -Djnp.port=3099 -Djnp.rmiPort=3098 -Dactivemq.remoting.netty.port=7445 -Dactivemq.remoting.netty.batch.port=7455" -./run.sh ../config/stand-alone/clustered</code></pre> - <li>finally, in the fourth terminal, start the example - <pre class="prettyprint"><code>./build.sh runRemote</code> (or <code>build.bat runRemote</code> on windows)</pre> - <p>The example connects to the three cluster nodes using JNDI (which are retrieved from - <a href="server0/client-jndi.properties">server0</a>, <a href="server1/client-jndi.properties">server1</a>, and - <a href="server2/client-jndi.properties">server2</a>' s JNDI properties file). The JNDI ports were specified - using the environment property <code>jnp.port</code> (or 1098 by default) when starting the 3 cluster nodes.</p> - - <p>For a description of the example code, please read the <a href="../clustered-topic/readme.html"> - clustered-topic example</a> which is very similar (it has 2 nodes while this example has 3 nodes). - - </body> -</html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java b/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java deleted file mode 100644 index 59427f8..0000000 --- a/examples/jms/clustered-standalone/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredStandaloneExample.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.artemis.jms.example; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.Topic; -import javax.naming.InitialContext; -import java.util.Hashtable; - -public class ClusteredStandaloneExample -{ - public static void main(final String[] args) throws Exception - { - Connection connection0 = null; - - Connection connection1 = null; - - Connection connection2 = null; - - InitialContext initialContext0 = null; - InitialContext initialContext1 = null; - InitialContext initialContext2 = null; - - try - { - 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"); - initialContext0 = new InitialContext(properties); - - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61617"); - initialContext1 = new InitialContext(properties); - - properties = new Hashtable<String, Object>(); - properties.put("java.naming.factory.initial", "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); - properties.put("connectionFactory.ConnectionFactory", "tcp://localhost:61618"); - initialContext2 = new InitialContext(properties); - - // First we demonstrate a distributed topic. - // We create a connection on each node, create a consumer on each connection and send some - // messages at a node and verify they are all received by all consumers - - ConnectionFactory cf0 = (ConnectionFactory)initialContext0.lookup("ConnectionFactory"); - - System.out.println("Got cf " + cf0); - - ConnectionFactory cf1 = (ConnectionFactory)initialContext1.lookup("ConnectionFactory"); - - System.out.println("Got cf " + cf1); - - ConnectionFactory cf2 = (ConnectionFactory)initialContext2.lookup("ConnectionFactory"); - - System.out.println("Got cf " + cf2); - - Topic topic = (Topic)initialContext0.lookup("topic/exampleTopic"); - - connection0 = cf0.createConnection(); - - connection1 = cf1.createConnection(); - - connection2 = cf2.createConnection(); - - connection0.start(); - - connection1.start(); - - connection2.start(); - - Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE); - - Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageConsumer messageConsumer0 = session0.createConsumer(topic); - - MessageConsumer messageConsumer1 = session1.createConsumer(topic); - - MessageConsumer messageConsumer2 = session2.createConsumer(topic); - - MessageProducer producer = session0.createProducer(topic); - - final int numMessages = 10; - - for (int i = 0; i < numMessages; i++) - { - TextMessage message = session0.createTextMessage("Message " + i); - - producer.send(message); - } - - for (int i = 0; i < numMessages; i++) - { - TextMessage message0 = (TextMessage)messageConsumer0.receive(2000); - - if (message0 == null) - { - throw new IllegalStateException(); - } - - // System.out.println("Received message " + message0.getText()); - - TextMessage message1 = (TextMessage)messageConsumer1.receive(2000); - - if (message1 == null) - { - throw new IllegalStateException(); - } - - // System.out.println("Received message " + message1.getText()); - - TextMessage message2 = (TextMessage)messageConsumer2.receive(2000); - - if (message2 == null) - { - throw new IllegalStateException(); - } - - System.out.println("Received message " + message2.getText()); - } - - producer.close(); - - messageConsumer0.close(); - - messageConsumer1.close(); - - messageConsumer2.close(); - } - finally - { - // Step 12. Be sure to close our JMS resources! - if (initialContext0 != null) - { - initialContext0.close(); - } - if (initialContext1 != null) - { - initialContext1.close(); - } - if (initialContext2 != null) - { - initialContext2.close(); - } - if (connection0 != null) - { - connection0.close(); - } - if (connection1 != null) - { - connection1.close(); - } - if (connection2 != null) - { - connection2.close(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 55675d0..0000000 --- a/examples/jms/clustered-standalone/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="urn:activemq" - xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - - <jms xmlns="urn:activemq:jms"> - <!--the topic used by the example--> - <topic name="exampleTopic"/> - </jms> - - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> - - <journal-directory>${data.dir:./data}/journal</journal-directory> - - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> - - <paging-directory>${data.dir:./data}/paging</paging-directory> - <!-- Connectors --> - - <connectors> - <connector name="netty-connector">tcp://localhost:61616</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> - </acceptors> - - <!-- Clustering configuration --> - <broadcast-groups> - <broadcast-group name="my-broadcast-group"> - <group-address>${udp-address:231.7.7.7}</group-address> - <group-port>9876</group-port> - <broadcast-period>100</broadcast-period> - <connector-ref>netty-connector</connector-ref> - </broadcast-group> - </broadcast-groups> - - <discovery-groups> - <discovery-group name="my-discovery-group"> - <group-address>${udp-address:231.7.7.7}</group-address> - <group-port>9876</group-port> - <refresh-timeout>10000</refresh-timeout> - </discovery-group> - </discovery-groups> - - <cluster-connections> - <cluster-connection name="my-cluster"> - <address>jms</address> - <connector-ref>netty-connector</connector-ref> - <retry-interval>500</retry-interval> - <use-duplicate-detection>true</use-duplicate-detection> - <message-load-balancing>STRICT</message-load-balancing> - <max-hops>1</max-hops> - <discovery-group-ref discovery-group-name="my-discovery-group"/> - </cluster-connection> - </cluster-connections> - - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="jms.topic.exampleTopic"> - <permission type="createDurableQueue" roles="guest"/> - <permission type="deleteDurableQueue" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - </security-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml deleted file mode 100644 index 78b0f2f..0000000 --- a/examples/jms/clustered-standalone/src/main/resources/activemq/server1/broker.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="urn:activemq" - xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - - <jms xmlns="urn:activemq:jms"> - <!--the topic used by the example--> - <topic name="exampleTopic"/> - </jms> - - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> - - <journal-directory>${data.dir:./data}/journal</journal-directory> - - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> - - <paging-directory>${data.dir:./data}/paging</paging-directory> - - <!-- Connectors --> - <connectors> - <connector name="netty-connector">tcp://localhost:61617</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61617</acceptor> - </acceptors> - - <!-- Clustering configuration --> - <broadcast-groups> - <broadcast-group name="my-broadcast-group"> - <group-address>${udp-address:231.7.7.7}</group-address> - <group-port>9876</group-port> - <broadcast-period>100</broadcast-period> - <connector-ref>netty-connector</connector-ref> - </broadcast-group> - </broadcast-groups> - - <discovery-groups> - <discovery-group name="my-discovery-group"> - <group-address>${udp-address:231.7.7.7}</group-address> - <group-port>9876</group-port> - <refresh-timeout>10000</refresh-timeout> - </discovery-group> - </discovery-groups> - - <cluster-connections> - <cluster-connection name="my-cluster"> - <address>jms</address> - <connector-ref>netty-connector</connector-ref> - <retry-interval>500</retry-interval> - <use-duplicate-detection>true</use-duplicate-detection> - <message-load-balancing>STRICT</message-load-balancing> - <max-hops>1</max-hops> - <discovery-group-ref discovery-group-name="my-discovery-group"/> - </cluster-connection> - </cluster-connections> - - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="jms.topic.exampleTopic"> - <permission type="createDurableQueue" roles="guest"/> - <permission type="deleteDurableQueue" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - </security-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml deleted file mode 100644 index 389914c..0000000 --- a/examples/jms/clustered-standalone/src/main/resources/activemq/server2/broker.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="urn:activemq" - xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - - <jms xmlns="urn:activemq:jms"> - <!--the topic used by the example--> - <topic name="exampleTopic"/> - </jms> - - <core xmlns="urn:activemq:core"> - - <bindings-directory>${data.dir:./data}/bindings</bindings-directory> - - <journal-directory>${data.dir:./data}/journal</journal-directory> - - <large-messages-directory>${data.dir:./data}/largemessages</large-messages-directory> - - <paging-directory>${data.dir:./data}/paging</paging-directory> - - <!-- Connectors --> - <connectors> - <connector name="netty-connector">tcp://localhost:61618</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61618</acceptor> - </acceptors> - - <!-- Clustering configuration --> - <broadcast-groups> - <broadcast-group name="my-broadcast-group"> - <group-address>${udp-address:231.7.7.7}</group-address> - <group-port>9876</group-port> - <broadcast-period>100</broadcast-period> - <connector-ref>netty-connector</connector-ref> - </broadcast-group> - </broadcast-groups> - - <discovery-groups> - <discovery-group name="my-discovery-group"> - <group-address>${udp-address:231.7.7.7}</group-address> - <group-port>9876</group-port> - <refresh-timeout>10000</refresh-timeout> - </discovery-group> - </discovery-groups> - - <cluster-connections> - <cluster-connection name="my-cluster"> - <address>jms</address> - <connector-ref>netty-connector</connector-ref> - <retry-interval>500</retry-interval> - <use-duplicate-detection>true</use-duplicate-detection> - <message-load-balancing>STRICT</message-load-balancing> - <max-hops>1</max-hops> - <discovery-group-ref discovery-group-name="my-discovery-group"/> - </cluster-connection> - </cluster-connections> - - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="jms.topic.exampleTopic"> - <permission type="createDurableQueue" roles="guest"/> - <permission type="deleteDurableQueue" roles="guest"/> - <permission type="createNonDurableQueue" roles="guest"/> - <permission type="deleteNonDurableQueue" roles="guest"/> - <permission type="consume" roles="guest"/> - <permission type="send" roles="guest"/> - </security-setting> - </security-settings> - - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-discovery/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/pom.xml b/examples/jms/clustered-static-discovery/pom.xml index 98fcc90..7a86bf7 100644 --- a/examples/jms/clustered-static-discovery/pom.xml +++ b/examples/jms/clustered-static-discovery/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-static-discovery-example</artifactId> + <artifactId>clustered-static-discovery</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Clustered Static Discovery Example</name> @@ -42,189 +43,206 @@ 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>${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>create3</id> - <goals> - <goal>create</goal> - </goals> - <configuration> - <instance>${basedir}/target/server3</instance> - <configuration>${basedir}/target/classes/activemq/server3</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>start3</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <spawn>true</spawn> - <location>${basedir}/target/server3</location> - <testURI>tcp://localhost:61619</testURI> - <args> - <param>run</param> - </args> - <name>server3</name> - </configuration> - </execution> - <execution> - <id>runClient</id> - <goals> - <goal>runClient</goal> - </goals> - <configuration> - <clientClass>org.apache.activemq.artemis.jms.example.StaticClusteredQueueExample</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> - <execution> - <id>stop3</id> - <goals> - <goal>cli</goal> - </goals> - <configuration> - <location>${basedir}/target/server3</location> - <args> - <param>stop</param> - </args> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.activemq.examples.jms</groupId> - <artifactId>artemis-jms-clustered-static-discovery-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>create3</id> + <goals> + <goal>create</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <instance>${basedir}/target/server3</instance> + <configuration>${basedir}/target/classes/activemq/server3</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> + <spawn>true</spawn> + <ignore>${noServer}</ignore> + <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>start3</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <spawn>true</spawn> + <location>${basedir}/target/server3</location> + <testURI>tcp://localhost:61619</testURI> + <args> + <param>run</param> + </args> + <name>server3</name> + </configuration> + </execution> + <execution> + <id>runClient</id> + <goals> + <goal>runClient</goal> + </goals> + <configuration> + <clientClass>org.apache.activemq.artemis.jms.example.StaticClusteredQueueExample</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> + <execution> + <id>stop3</id> + <goals> + <goal>cli</goal> + </goals> + <configuration> + <ignore>${noServer}</ignore> + <location>${basedir}/target/server3</location> + <args> + <param>stop</param> + </args> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.examples.jms</groupId> + <artifactId>clustered-static-discovery</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-static-discovery/readme.html ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/readme.html b/examples/jms/clustered-static-discovery/readme.html index 71a4501..c1347dc 100644 --- a/examples/jms/clustered-static-discovery/readme.html +++ b/examples/jms/clustered-static-discovery/readme.html @@ -26,6 +26,7 @@ under the License. </head> <body onload="prettyPrint()"> <h1>JMS Load Balanced Static Clustered Queue 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 JMS queue deployed on two different nodes. The two nodes are configured to form a cluster from a <em>static</em> list of nodes.</p> @@ -53,147 +54,5 @@ under the License. </pre> <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 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> </body> </html> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java b/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java index 4e0ac26..6716075 100644 --- a/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java +++ b/examples/jms/clustered-static-discovery/src/main/java/org/apache/activemq/artemis/jms/example/StaticClusteredQueueExample.java @@ -16,8 +16,6 @@ */ package org.apache.activemq.artemis.jms.example; -import org.apache.activemq.artemis.util.ServerUtil; - import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.MessageConsumer; @@ -25,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.util.ServerUtil; /** * A simple example that demonstrates server side load-balancing of messages between the queue instances on different @@ -46,22 +46,13 @@ public class StaticClusteredQueueExample Connection connection3 = null; - InitialContext ic0 = null; - try { - // Step 1. Get an initial context for looking up JNDI from server 3 - 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:61619"); - properties.put("queue.queue/exampleQueue", "exampleQueue"); - ic0 = new InitialContext(properties); + // Step 2. Use direct instantiation (or JNDI if you like) + Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); - // 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 3. new JMS Connection Factory object from JNDI on server 3 + ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61619"); //grab an initial connection and wait, in reality you wouldn't do it this way but since we want to ensure an // equal load balance we do this and then create 4 connections round robined @@ -189,11 +180,6 @@ public class StaticClusteredQueueExample { connection3.close(); } - - if (ic0 != null) - { - ic0.close(); - } } } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dd820318/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml index 30bee5d..b1bfd11 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server0/broker.xml +++ b/examples/jms/clustered-static-discovery/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-static-discovery/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml index f2f2565..0412576 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server1/broker.xml +++ b/examples/jms/clustered-static-discovery/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-static-discovery/src/main/resources/activemq/server2/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml index e9e5f08..98b8f04 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml +++ b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml @@ -26,13 +26,13 @@ <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-static-discovery/src/main/resources/activemq/server3/broker.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml index 0ebc2d0..40bef87 100644 --- a/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml +++ b/examples/jms/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml @@ -26,13 +26,13 @@ <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-static-oneway/pom.xml ---------------------------------------------------------------------- diff --git a/examples/jms/clustered-static-oneway/pom.xml b/examples/jms/clustered-static-oneway/pom.xml index 991a624..f3d8db5 100644 --- a/examples/jms/clustered-static-oneway/pom.xml +++ b/examples/jms/clustered-static-oneway/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-static-oneway-example</artifactId> + <artifactId>clustered-static-oneway</artifactId> <packaging>jar</packaging> <name>ActiveMQ Artemis JMS Clustered Static One Way Example</name> @@ -42,151 +43,165 @@ 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>${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.ClusterStaticOnewayExample</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-static-oneway-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.ClusterStaticOnewayExample</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-static-oneway</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project>
