activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [22/48] activemq-artemis git commit: renaming broker-features -> features on examples
Date Thu, 13 Aug 2015 04:13:40 GMT
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml b/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml
new file mode 100644
index 0000000..98b8f04
--- /dev/null
+++ b/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server2/broker.xml
@@ -0,0 +1,79 @@
+<!--
+  ~ 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 queue used by the example-->
+      <queue name="exampleQueue"/>
+   </jms>
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./data/paging</paging-directory>
+
+      <!-- Connectors -->
+      <connectors>
+         <connector name="netty-connector">tcp://localhost:61618</connector>
+         <!-- connector to the server0 -->
+         <connector name="server0-connector">tcp://localhost:61616</connector>
+      </connectors>
+
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">tcp://localhost:61618</acceptor>
+      </acceptors>
+
+      <!-- Clustering configuration -->
+      <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>
+            <static-connectors>
+               <connector-ref>server0-connector</connector-ref>
+            </static-connectors>
+         </cluster-connection>
+      </cluster-connections>
+
+      <!-- Other config -->
+
+      <security-settings>
+         <!--security for example queue-->
+         <security-setting match="jms.queue.exampleQueue">
+            <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/6b17d966/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml b/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml
new file mode 100644
index 0000000..40bef87
--- /dev/null
+++ b/examples/features/clustered/clustered-static-discovery/src/main/resources/activemq/server3/broker.xml
@@ -0,0 +1,79 @@
+<!--
+  ~ 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 queue used by the example-->
+      <queue name="exampleQueue"/>
+   </jms>
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./data/paging</paging-directory>
+
+      <!-- Connectors -->
+      <connectors>
+         <connector name="netty-connector">tcp://localhost:61619</connector>
+         <!-- connector to the server0 -->
+         <connector name="server0-connector">tcp://localhost:61616</connector>
+      </connectors>
+
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">tcp://localhost:61619</acceptor>
+      </acceptors>
+
+      <!-- Clustering configuration -->
+      <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>
+            <static-connectors>
+               <connector-ref>server0-connector</connector-ref>
+            </static-connectors>
+         </cluster-connection>
+      </cluster-connections>
+
+      <!-- Other config -->
+
+      <security-settings>
+         <!--security for example queue-->
+         <security-setting match="jms.queue.exampleQueue">
+            <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/6b17d966/examples/features/clustered/clustered-static-oneway/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-oneway/pom.xml b/examples/features/clustered/clustered-static-oneway/pom.xml
new file mode 100644
index 0000000..18a303c
--- /dev/null
+++ b/examples/features/clustered/clustered-static-oneway/pom.xml
@@ -0,0 +1,198 @@
+<?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.clustered</groupId>
+      <artifactId>broker-clustered</artifactId>
+      <version>1.0.1-SNAPSHOT</version>
+   </parent>
+
+   <artifactId>clustered-static-oneway</artifactId>
+   <packaging>jar</packaging>
+   <name>ActiveMQ Artemis JMS Clustered Static One Way Example</name>
+
+   <properties>
+      <activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
+   </properties>
+
+   <dependencies>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-cli</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-jms-client</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+   </dependencies>
+
+   <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.clustered</groupId>
+                  <artifactId>clustered-static-oneway</artifactId>
+                  <version>${project.version}</version>
+               </dependency>
+            </dependencies>
+         </plugin>
+      </plugins>
+   </build>
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/clustered-static-oneway/readme.html
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-oneway/readme.html b/examples/features/clustered/clustered-static-oneway/readme.html
new file mode 100644
index 0000000..04334a5
--- /dev/null
+++ b/examples/features/clustered/clustered-static-oneway/readme.html
@@ -0,0 +1,64 @@
+<!--
+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>ActiveMQ Artemis JMS Load Balanced Static Clustered Queue 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 Load Balanced Static Clustered One Way 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 three different nodes. The three nodes are configured to form a one way cluster
+       from a <em>static</em> list of nodes. </p>
+     <p>A one way cluster is different from a symmetrical cluster in that each node is only connected to one another node in
+     a chain type fashion, so server 0 -> server 1 -> server 2</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>all</b> consumers receive the sent messages
+     in a round-robin fashion.</p>
+     <p>In other words, ActiveMQ Artemis <b>load balances</b> the sent messages across all consumers on the cluster</p>
+     <p>This example uses JNDI to lookup the JMS Queue and ConnectionFactory objects. If you prefer not to use
+     JNDI, these could be instantiated directly.</p>
+     <p>Here's the relevant snippet from the server configuration, which tells the server to form a one way cluster between the three nodes
+     and to load balance the messages between the nodes. Note that we have set <em>allow-direct-connections-only</em> to true,
+     this means that this server will only ever connect the address's specified in the list of connectors. ALso notice
+     that <em>max-hops</em> is 2, this is because server 0 is not directly connected to server 2, 2 hops in fact, so we
+     allow any updates from servers up to 2 hops away</p>
+     <pre class="prettyprint">
+     <code>
+     &lt;cluster-connection name="my-cluster"&gt;
+        &lt;address&gt;jms&lt;/address&gt;
+        &lt;connector-ref>netty-connector&lt;/connector-ref>
+        &lt;retry-interval&gt;500&lt;/retry-interval&gt;
+        &lt;use-duplicate-detection&gt;true&lt;/use-duplicate-detection&gt;
+        &lt;message-load-balancing&gt;STRICT&lt;/message-load-balancing&gt;
+        &lt;max-hops&gt;2&lt;/max-hops&gt;
+        &lt;static-connectors allow-direct-connections-only="true"&gt;
+            &lt;connector-ref>server1-connector&lt;/connector-ref&gt;
+         &lt;/static-connectors&gt;
+     &lt;/cluster-connection&gt;
+     </code>
+     </pre>
+     <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering
+     section of the user manual.</p>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java b/examples/features/clustered/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java
new file mode 100644
index 0000000..0397907
--- /dev/null
+++ b/examples/features/clustered/clustered-static-oneway/src/main/java/org/apache/activemq/artemis/jms/example/ClusterStaticOnewayExample.java
@@ -0,0 +1,159 @@
+/*
+ * 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.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+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
+ * nodes of the cluster. The cluster is created from a static list of nodes.
+ */
+public class ClusterStaticOnewayExample {
+
+   public static void main(final String[] args) throws Exception {
+      Connection initialConnection = null;
+
+      Connection connection0 = null;
+
+      Connection connection1 = null;
+
+      Connection connection2 = null;
+
+      try {
+         // Step 2. Instantiate Queue
+         Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
+
+         // Step 3. Look-up a JMS Connection Factory object from JNDI on server 0
+         ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616");
+
+         //step 4. 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
+         initialConnection = cf0.createConnection();
+
+         Thread.sleep(2000);
+         // Step 5. We create a JMS Connection connection0 which is a connection to server 0
+         connection0 = cf0.createConnection();
+
+         // Step 6. We create a JMS Connection connection1 which is a connection to server 1
+         connection1 = cf0.createConnection();
+
+         // Step 7. We create a JMS Connection connection0 which is a connection to server 2
+         connection2 = cf0.createConnection();
+
+         // Step 8. 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
+         Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 10. We create a JMS Session on server 2
+         Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 11. We start the connections to ensure delivery occurs on them
+         connection0.start();
+
+         connection1.start();
+
+         connection2.start();
+
+         // Step 12. We create JMS MessageConsumer objects on server 0,server 1 and server 2
+         MessageConsumer consumer0 = session0.createConsumer(queue);
+
+         MessageConsumer consumer1 = session1.createConsumer(queue);
+
+         MessageConsumer consumer2 = session2.createConsumer(queue);
+
+         Thread.sleep(4000);
+
+         int con0Node = ServerUtil.getServer(connection0);
+         int con1Node = ServerUtil.getServer(connection1);
+         int con2Node = ServerUtil.getServer(connection2);
+
+         System.out.println("con0Node = " + con0Node);
+         System.out.println("con1Node = " + con1Node);
+         System.out.println("con2Node = " + con2Node);
+
+         if (con0Node + con1Node + con2Node != 3) {
+            throw new IllegalStateException("connections not load balanced");
+         }
+         // Step 13. We create a JMS MessageProducer object on server 0
+         Session sendSession = ServerUtil.getServerConnection(0, connection0, connection1, connection2).createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageProducer producer = sendSession.createProducer(queue);
+
+         // Step 14. We send some messages to server 0
+
+         final int numMessages = 18;
+
+         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());
+         }
+         Thread.sleep(2000);
+         // Step 15. We now consume those messages on *both* server 0,server 1 and 2.
+         // We note the messages have been distributed between servers in a round robin fashion
+         // JMS Queues implement point-to-point message where each message is only ever consumed by a
+         // maximum of one consumer
+
+         for (int i = 0; i < numMessages; i += 3) {
+            TextMessage message0 = (TextMessage) consumer0.receive(5000);
+
+            System.out.println("Got message: " + message0.getText() + " from node " + con0Node);
+
+            TextMessage message1 = (TextMessage) consumer1.receive(5000);
+
+            System.out.println("Got message: " + message1.getText() + " from node " + con1Node);
+
+            TextMessage message2 = (TextMessage) consumer2.receive(5000);
+
+            System.out.println("Got message: " + message2.getText() + " from node " + con2Node);
+         }
+      }
+      finally {
+         // Step 15. Be sure to close our resources!
+
+         if (initialConnection != null) {
+            initialConnection.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/6b17d966/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml b/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml
new file mode 100644
index 0000000..3e86ed3
--- /dev/null
+++ b/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server0/broker.xml
@@ -0,0 +1,79 @@
+<!--
+  ~ 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 queue used by the example-->
+      <queue name="exampleQueue"/>
+   </jms>
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./data/paging</paging-directory>
+
+      <!-- Connectors -->
+
+      <connectors>
+         <connector name="netty-connector">tcp://localhost:61616</connector>
+         <!-- connector to the server1 -->
+         <connector name="server1-connector">tcp://localhost:61617</connector>
+      </connectors>
+
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
+      </acceptors>
+
+      <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>2</max-hops>
+            <static-connectors allow-direct-connections-only="true">
+               <connector-ref>server1-connector</connector-ref>
+            </static-connectors>
+         </cluster-connection>
+      </cluster-connections>
+
+      <!-- Other config -->
+
+      <security-settings>
+         <!--security for example queue-->
+         <security-setting match="jms.queue.exampleQueue">
+            <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/6b17d966/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml b/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml
new file mode 100644
index 0000000..1464ea9
--- /dev/null
+++ b/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server1/broker.xml
@@ -0,0 +1,79 @@
+<!--
+  ~ 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 queue used by the example-->
+      <queue name="exampleQueue"/>
+   </jms>
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./data/paging</paging-directory>
+
+      <!-- Connectors -->
+      <connectors>
+         <connector name="netty-connector">tcp://localhost:61617</connector>
+         <!-- connector to the server0 -->
+         <connector name="server2-connector">tcp://localhost:61618</connector>
+      </connectors>
+
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">tcp://localhost:61617</acceptor>
+      </acceptors>
+
+      <!-- Clustering configuration -->
+      <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>2</max-hops>
+            <static-connectors allow-direct-connections-only="true">
+               <connector-ref>server2-connector</connector-ref>
+            </static-connectors>
+         </cluster-connection>
+      </cluster-connections>
+
+      <!-- Other config -->
+
+      <security-settings>
+         <!--security for example queue-->
+         <security-setting match="jms.queue.exampleQueue">
+            <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/6b17d966/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml b/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml
new file mode 100644
index 0000000..b1043f5
--- /dev/null
+++ b/examples/features/clustered/clustered-static-oneway/src/main/resources/activemq/server2/broker.xml
@@ -0,0 +1,74 @@
+<!--
+  ~ 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 queue used by the example-->
+      <queue name="exampleQueue"/>
+   </jms>
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./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 -->
+      <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>2</max-hops>
+         </cluster-connection>
+      </cluster-connections>
+
+      <!-- Other config -->
+
+      <security-settings>
+         <!--security for example queue-->
+         <security-setting match="jms.queue.exampleQueue">
+            <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/6b17d966/examples/features/clustered/clustered-topic/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-topic/pom.xml b/examples/features/clustered/clustered-topic/pom.xml
new file mode 100644
index 0000000..bff7c70
--- /dev/null
+++ b/examples/features/clustered/clustered-topic/pom.xml
@@ -0,0 +1,153 @@
+<?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.clustered</groupId>
+      <artifactId>broker-clustered</artifactId>
+      <version>1.0.1-SNAPSHOT</version>
+   </parent>
+
+   <artifactId>clustered-topic</artifactId>
+   <packaging>jar</packaging>
+   <name>ActiveMQ Artemis JMS Clustered Topic Example</name>
+
+   <properties>
+      <activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
+   </properties>
+
+   <dependencies>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-jms-client</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+   </dependencies>
+
+   <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.ClusteredTopicExample</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.clustered</groupId>
+                  <artifactId>clustered-topic</artifactId>
+                  <version>${project.version}</version>
+               </dependency>
+            </dependencies>
+         </plugin>
+      </plugins>
+   </build>
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/clustered-topic/readme.html
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-topic/readme.html b/examples/features/clustered/clustered-topic/readme.html
new file mode 100644
index 0000000..e46fca8
--- /dev/null
+++ b/examples/features/clustered/clustered-topic/readme.html
@@ -0,0 +1,55 @@
+<!--
+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>ActiveMQ Artemis JMS Clustered Topic 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 Topic 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 Topic deployed on two different nodes. The two nodes are configured to form a cluster.</p>
+     <p>We then create a subscriber on the topic 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> subscribers receive all the
+     sent messages.</p>
+     <p>A JMS Topic is an example of <b>publish-subscribe</b> messaging where all subscribers receive all the
+     messages sent to the topic (assuming they have no message selectors).</p>
+     <p>This example uses JNDI to lookup the JMS Queue and ConnectionFactory objects. If you prefer not to use
+     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>
+     <pre class="prettyprint">
+     <code>&lt;cluster-connection name="my-cluster"&gt;
+        &lt;address&gt;jms&lt;/address&gt;
+        &lt;retry-interval&gt;500&lt;/retry-interval&gt;
+        &lt;use-duplicate-detection&gt;true&lt;/use-duplicate-detection&gt;
+        &lt;message-load-balancing&gt;STRICT&lt;/message-load-balancing&gt;
+        &lt;max-hops&gt;1&lt;/max-hops&gt;
+        &lt;discovery-group-ref discovery-group-name="my-discovery-group"/&gt;
+     &lt;/cluster-connection&gt;
+     </code>
+     </pre>
+     <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering
+     section of the user manual.</p>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java b/examples/features/clustered/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java
new file mode 100644
index 0000000..f3ce9a0
--- /dev/null
+++ b/examples/features/clustered/clustered-topic/src/main/java/org/apache/activemq/artemis/jms/example/ClusteredTopicExample.java
@@ -0,0 +1,129 @@
+/*
+ * 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 org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * A simple example that shows a JMS Topic clustered across two nodes of a cluster.
+ * Messages are sent on one node and received by consumers on both nodes.
+ */
+public class ClusteredTopicExample {
+
+   public static void main(final String[] args) throws Exception {
+      Connection connection0 = null;
+
+      Connection connection1 = null;
+
+      InitialContext ic0 = null;
+
+      InitialContext ic1 = null;
+
+      try {
+
+         // Step 1. Instantiate topic
+         Topic topic = ActiveMQJMSClient.createTopic("exampleTopic");
+
+         // Step 2. Look-up a JMS Connection Factory object from JNDI on server 0
+         ConnectionFactory cf0 = new ActiveMQConnectionFactory("tcp://localhost:61616");
+
+         // Step 3. Look-up a JMS Connection Factory object from JNDI on server 1
+         ConnectionFactory cf1 = new ActiveMQConnectionFactory("tcp://localhost:61617");
+
+         // Step 4. We create a JMS Connection connection0 which is a connection to server 0
+         connection0 = cf0.createConnection();
+
+         // Step 5. We create a JMS Connection connection1 which is a connection to server 1
+         connection1 = cf1.createConnection();
+
+         // Step 6. We create a JMS Session on server 0
+         Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 7. We create a JMS Session on server 1
+         Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 8. We start the connections to ensure delivery occurs on them
+         connection0.start();
+
+         connection1.start();
+
+         // Step 9. We create JMS MessageConsumer objects on server 0 and server 1
+         MessageConsumer consumer0 = session0.createConsumer(topic);
+
+         MessageConsumer consumer1 = session1.createConsumer(topic);
+
+         Thread.sleep(1000);
+
+         // Step 10. We create a JMS MessageProducer object on server 0
+         MessageProducer producer = session0.createProducer(topic);
+
+         // Step 11. We send some messages to server 0
+
+         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());
+         }
+
+         // Step 12. We now consume those messages on *both* server 0 and server 1.
+         // We note that all messages have been consumed by *both* consumers.
+         // JMS Topics implement *publish-subscribe* messaging where all consumers get a copy of all messages
+
+         for (int i = 0; i < numMessages; i++) {
+            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");
+         }
+      }
+      finally {
+         // Step 15. Be sure to close our JMS resources!
+         if (connection0 != null) {
+            connection0.close();
+         }
+
+         if (connection1 != null) {
+            connection1.close();
+         }
+
+         if (ic0 != null) {
+            ic0.close();
+         }
+
+         if (ic1 != null) {
+            ic1.close();
+         }
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/clustered-topic/src/main/resources/activemq/server0/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-topic/src/main/resources/activemq/server0/broker.xml b/examples/features/clustered/clustered-topic/src/main/resources/activemq/server0/broker.xml
new file mode 100644
index 0000000..a4e8dde
--- /dev/null
+++ b/examples/features/clustered/clustered-topic/src/main/resources/activemq/server0/broker.xml
@@ -0,0 +1,97 @@
+<?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/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./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 configuration -->
+
+      <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/6b17d966/examples/features/clustered/clustered-topic/src/main/resources/activemq/server1/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/clustered-topic/src/main/resources/activemq/server1/broker.xml b/examples/features/clustered/clustered-topic/src/main/resources/activemq/server1/broker.xml
new file mode 100644
index 0000000..78beec3
--- /dev/null
+++ b/examples/features/clustered/clustered-topic/src/main/resources/activemq/server1/broker.xml
@@ -0,0 +1,95 @@
+<?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/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./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 configuration -->
+
+      <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/6b17d966/examples/features/clustered/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/pom.xml b/examples/features/clustered/pom.xml
new file mode 100644
index 0000000..49b12e2
--- /dev/null
+++ b/examples/features/clustered/pom.xml
@@ -0,0 +1,77 @@
+<?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.clustered</groupId>
+      <artifactId>broker-features</artifactId>
+      <version>1.0.1-SNAPSHOT</version>
+   </parent>
+
+   <groupId>org.apache.activemq.examples.clustered</groupId>
+   <artifactId>broker-clustered</artifactId>
+   <packaging>pom</packaging>
+   <name>ActiveMQ Artemis Clustered Examples</name>
+
+   <!-- Properties -->
+   <properties>
+      <!--
+      Explicitly declaring the source encoding eliminates the following
+      message: [WARNING] Using platform encoding (UTF-8 actually) to copy
+      filtered resources, i.e. build is platform dependent!
+      -->
+      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+      <activemq.basedir>${project.basedir}/../../..</activemq.basedir>
+   </properties>
+
+   <profiles>
+      <profile>
+         <id>examples</id>
+         <modules>
+            <module>client-side-load-balancing</module>
+            <module>clustered-durable-subscription</module>
+            <module>clustered-grouping</module>
+            <module>clustered-jgroups</module>
+            <module>clustered-queue</module>
+            <module>clustered-static-oneway</module>
+            <module>clustered-static-discovery</module>
+            <module>clustered-topic</module>
+            <module>queue-message-redistribution</module>
+            <module>symmetric-cluster</module>
+         </modules>
+      </profile>
+      <profile>
+         <id>release</id>
+         <modules>
+            <module>clustered-durable-subscription</module>
+            <module>clustered-grouping</module>
+            <module>clustered-jgroups</module>
+            <module>clustered-queue</module>
+            <module>clustered-static-oneway</module>
+            <module>clustered-static-discovery</module>
+            <module>clustered-topic</module>
+            <module>queue-message-redistribution</module>
+            <module>symmetric-cluster</module>
+         </modules>
+      </profile>
+   </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/queue-message-redistribution/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/queue-message-redistribution/pom.xml b/examples/features/clustered/queue-message-redistribution/pom.xml
new file mode 100644
index 0000000..4816ad0
--- /dev/null
+++ b/examples/features/clustered/queue-message-redistribution/pom.xml
@@ -0,0 +1,155 @@
+<?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.clustered</groupId>
+      <artifactId>broker-clustered</artifactId>
+      <version>1.0.1-SNAPSHOT</version>
+   </parent>
+
+   <artifactId>queue-message-redistribution</artifactId>
+   <packaging>jar</packaging>
+   <name>ActiveMQ Artemis JMS Queue Message Redistribution Example</name>
+
+   <properties>
+      <activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
+   </properties>
+
+   <dependencies>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-jms-client</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+   </dependencies>
+
+   <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.QueueMessageRedistributionExample
+                     </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.clustered</groupId>
+                  <artifactId>queue-message-redistribution</artifactId>
+                  <version>${project.version}</version>
+               </dependency>
+            </dependencies>
+         </plugin>
+      </plugins>
+   </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/queue-message-redistribution/readme.html
----------------------------------------------------------------------
diff --git a/examples/features/clustered/queue-message-redistribution/readme.html b/examples/features/clustered/queue-message-redistribution/readme.html
new file mode 100644
index 0000000..35fcafe
--- /dev/null
+++ b/examples/features/clustered/queue-message-redistribution/readme.html
@@ -0,0 +1,61 @@
+<!--
+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>ActiveMQ Artemis Message Redistribution 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>Message Redistribution 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 message redistribution between queues with the same name deployed in different
+     nodes of a cluster.</p>
+     <p>As demontrated in the clustered queue example, if queues with the same name are deployed on different nodes of
+     a cluster, ActiveMQ Artemis can be configured to load balance messages between the nodes on the server side.</p>
+     <p>However, if the consumer(s) on a particular node are closed, then messages in the queue at that node can
+     appear to be stranded, since they have no local consumers.</p>
+     <p>If this is undesirable, ActiveMQ Artemis can be configured to <b>redistribute</b> messages from the node
+     with no consumers, to nodes where there are consumers. If the consumers have JMS selectors set on them, then they
+     will only be redistributed to nodes with consumers whose selectors match.</p>
+     <p>By default, message redistribution is disabled, but can be enabled by specifying some AddressSettings configuration
+     in either <code>activemq-queues.xml</code> or <code>broker.xml</code></p>
+     <p>Setting <code>redistribution-delay</code> to <code>0</code> will cause redistribution to occur immediately
+     once there are no more matching consumers on a particular queue instance. Setting it to a positive value > 0 specifies
+     a delay in milliseconds before attempting to redistribute. The delay is useful in the case that another consumer is
+     likely to be created on the queue, to avoid unnecessary redistribution.</p>
+     <p>Here's the relevant snippet from the <code>activemq-queues.xml</code> configuration, which tells the server
+     to use a redistribution delay of <code>0</code> on any jms queues, i.e. any queues whose name starts with
+     <code>jms.</code></p>
+     <pre class="prettyprint">
+     <code>
+  &lt;address-setting match="jms.#"&gt;
+      &lt;redistribution-delay&gt;0&lt;/redistribution-delay&gt;
+   &lt;/address-setting&gt;
+   </code>
+     </pre>
+     <p>For more information on ActiveMQ Artemis load balancing, and clustering in general, please see the clustering
+     section of the user manual.</p>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java
----------------------------------------------------------------------
diff --git a/examples/features/clustered/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java b/examples/features/clustered/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java
new file mode 100644
index 0000000..b3c056b
--- /dev/null
+++ b/examples/features/clustered/queue-message-redistribution/src/main/java/org/apache/activemq/artemis/jms/example/QueueMessageRedistributionExample.java
@@ -0,0 +1,145 @@
+/*
+ * 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.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+
+/**
+ * This example demonstrates a queue with the same name deployed on two nodes of a cluster.
+ * Messages are initially round robin'd between both nodes of the cluster.
+ * The consumer on one of the nodes is then closed, and we demonstrate that the "stranded" messages
+ * are redistributed to the other node which has a consumer so they can be consumed.
+ */
+public class QueueMessageRedistributionExample {
+
+   public static void main(final String[] args) throws Exception {
+      Connection connection0 = null;
+
+      Connection connection1 = null;
+
+      try {
+         // Step 2. Look-up the JMS Queue object from JNDI
+         Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");
+
+         // Step 3. Look-up a JMS Connection Factory object from JNDI 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 = new ActiveMQConnectionFactory("tcp://localhost:61617");
+
+         // Step 6. 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
+         connection1 = cf1.createConnection();
+
+         // Step 8. We create a JMS Session on server 0, note the session is CLIENT_ACKNOWLEDGE
+         Session session0 = connection0.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+         // Step 9. We create a JMS Session on server 1, note the session is CLIENT_ACKNOWLEDGE
+         Session session1 = connection1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+         // Step 10. We start the connections to ensure delivery occurs on them
+         connection0.start();
+
+         connection1.start();
+
+         // Step 11. We create JMS MessageConsumer objects on server 0 and server 1
+         MessageConsumer consumer0 = session0.createConsumer(queue);
+
+         MessageConsumer consumer1 = session1.createConsumer(queue);
+
+         Thread.sleep(1000);
+
+         // Step 12. We create a JMS MessageProducer object on server 0
+         MessageProducer producer = session0.createProducer(queue);
+
+         // Step 13. We send some messages to server 0
+
+         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());
+         }
+
+         // Step 14. 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
+         // JMS Queues implement point-to-point message where each message is only ever consumed by a
+         // maximum of one consumer
+
+         TextMessage message0 = null;
+
+         TextMessage message1 = null;
+
+         for (int i = 0; i < numMessages; i += 2) {
+            message0 = (TextMessage) consumer0.receive(5000);
+
+            System.out.println("Got message: " + message0.getText() + " from node 0");
+
+            message1 = (TextMessage) consumer1.receive(5000);
+
+            System.out.println("Got message: " + message1.getText() + " from node 1");
+         }
+
+         // Step 15. We acknowledge the messages consumed on node 0. The sessions are CLIENT_ACKNOWLEDGE so
+         // messages will not get acknowledged until they are explicitly acknowledged.
+         // Note that we *do not* acknowledge the message consumed on node 1 yet.
+         message0.acknowledge();
+
+         // Step 16. We now close the session and consumer on node 1. (Closing the session automatically closes the
+         // consumer)
+         session1.close();
+
+         // Step 17. Since there is no more consumer on node 1, the messages on node 1 are now stranded (no local
+         // consumers)
+         // so ActiveMQ Artemis will redistribute them to node 0 so they can be consumed.
+
+         for (int i = 0; i < numMessages; i += 2) {
+            message0 = (TextMessage) consumer0.receive(5000);
+
+            System.out.println("Got message: " + message0.getText() + " from node 0");
+         }
+
+         // Step 18. We ack the messages.
+         message0.acknowledge();
+      }
+      finally {
+         // Step 18. Be sure to close our resources!
+
+         if (connection0 != null) {
+            connection0.close();
+         }
+
+         if (connection1 != null) {
+            connection1.close();
+         }
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6b17d966/examples/features/clustered/queue-message-redistribution/src/main/resources/activemq/server0/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/clustered/queue-message-redistribution/src/main/resources/activemq/server0/broker.xml b/examples/features/clustered/queue-message-redistribution/src/main/resources/activemq/server0/broker.xml
new file mode 100644
index 0000000..70ff4d4
--- /dev/null
+++ b/examples/features/clustered/queue-message-redistribution/src/main/resources/activemq/server0/broker.xml
@@ -0,0 +1,106 @@
+<?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 queue used by the example-->
+      <queue name="exampleQueue"/>
+   </jms>
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/bindings</bindings-directory>
+
+      <journal-directory>./data/journal</journal-directory>
+
+      <large-messages-directory>./data/largemessages</large-messages-directory>
+
+      <paging-directory>./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>ON_DEMAND</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.queue.exampleQueue">
+            <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>
+
+      <address-settings>
+         <!-- We set a redistribution delay of zero on all jms queues and topic subscriptions
+         Default redistribution delay as -1 which means "disable redistribution"
+         Setting it to a value > 0 means how long to wait before redistributing, if a consumer is closed
+         then another one quickly recreated you might want to set it thus, to avoid unnecessary
+         redistribution -->
+         <address-setting match="jms.#">
+            <redistribution-delay>0</redistribution-delay>
+         </address-setting>
+      </address-settings>
+
+   </core>
+</configuration>


Mime
View raw message