[jboss-cvs] JBoss Messaging SVN: r6423 - in trunk: examples/jms and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 14 12:28:56 EDT 2009


Author: timfox
Date: 2009-04-14 12:28:56 -0400 (Tue, 14 Apr 2009)
New Revision: 6423

Added:
   trunk/examples/jms/queue-message-redistribution/
   trunk/examples/jms/queue-message-redistribution/build.xml
   trunk/examples/jms/queue-message-redistribution/readme.html
   trunk/examples/jms/queue-message-redistribution/server0/
   trunk/examples/jms/queue-message-redistribution/server0/client-jndi.properties
   trunk/examples/jms/queue-message-redistribution/server0/jbm-configuration.xml
   trunk/examples/jms/queue-message-redistribution/server0/jbm-jms.xml
   trunk/examples/jms/queue-message-redistribution/server0/jbm-queues.xml
   trunk/examples/jms/queue-message-redistribution/server0/jbm-security.xml
   trunk/examples/jms/queue-message-redistribution/server0/jbm-standalone-beans.xml
   trunk/examples/jms/queue-message-redistribution/server1/
   trunk/examples/jms/queue-message-redistribution/server1/client-jndi.properties
   trunk/examples/jms/queue-message-redistribution/server1/jbm-configuration.xml
   trunk/examples/jms/queue-message-redistribution/server1/jbm-jms.xml
   trunk/examples/jms/queue-message-redistribution/server1/jbm-queues.xml
   trunk/examples/jms/queue-message-redistribution/server1/jbm-security.xml
   trunk/examples/jms/queue-message-redistribution/server1/jbm-standalone-beans.xml
   trunk/examples/jms/queue-message-redistribution/src/
   trunk/examples/jms/queue-message-redistribution/src/org/
   trunk/examples/jms/queue-message-redistribution/src/org/jboss/
   trunk/examples/jms/queue-message-redistribution/src/org/jboss/jms/
   trunk/examples/jms/queue-message-redistribution/src/org/jboss/jms/example/
   trunk/examples/jms/queue-message-redistribution/src/org/jboss/jms/example/QueueMessageRedistributionExample.java
Modified:
   trunk/.classpath
   trunk/src/main/org/jboss/messaging/core/deployers/impl/AddressSettingsDeployer.java
   trunk/src/schemas/jbm-queues.xsd
Log:
message redistribution example

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-04-14 16:28:02 UTC (rev 6422)
+++ trunk/.classpath	2009-04-14 16:28:56 UTC (rev 6423)
@@ -23,6 +23,7 @@
 	<classpathentry kind="src" path="examples/jms/application-layer-failover/src"/>
 	<classpathentry kind="src" path="examples/jms/clustered-queue/src"/>
 	<classpathentry kind="src" path="examples/jms/clustered-topic/src"/>
+	<classpathentry kind="src" path="examples/jms/queue-message-redistribution/src"/>
 	<classpathentry kind="src" path="examples/jms/clustered-durable-subscription/src"/>
 	<classpathentry kind="src" path="examples/jms/browser/src"/>
 	<classpathentry kind="src" path="examples/jms/durable-subscription/src"/>

Added: trunk/examples/jms/queue-message-redistribution/build.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/build.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/build.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+
+<!-- =========================================================================================== -->
+<!--                                                                                             -->
+<!-- JBoss, Home of Professional Open Source                                                     -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated                        -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a                        -->
+<!-- full listing of individual contributors.                                                    -->
+<!--                                                                                             -->
+<!-- This is free software; you can redistribute it and/or modify it                             -->
+<!-- under the terms of the GNU Lesser General Public License as                                 -->
+<!-- published by the Free Software Foundation; either version 2.1 of                            -->
+<!-- the License, or (at your option) any later version.                                         -->
+<!--                                                                                             -->
+<!-- This software is distributed in the hope that it will be useful,                            -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of                              -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU                            -->
+<!-- Lesser General Public License for more details.                                             -->
+<!--                                                                                             -->
+<!-- You should have received a copy of the GNU Lesser General Public                            -->
+<!-- License along with this software; if not, write to the Free                                 -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA                          -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org.                                    -->
+<!--                                                                                             -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging JMS Clustered Queue Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.QueueMessageRedistributionExample"/>
+         <param name="jbm.example.beans.file" value="server0 server1"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.QueueMessageRedistributionExample"/>
+         <param name="jbm.example.runServer" value="false"/>
+      </antcall>
+   </target>
+
+</project>

Added: trunk/examples/jms/queue-message-redistribution/readme.html
===================================================================
--- trunk/examples/jms/queue-message-redistribution/readme.html	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/readme.html	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,224 @@
+<html>
+  <head>
+    <title>JBoss Messaging Message Redistribution Example</title>
+    <link rel="stylesheet" type="text/css" href="../common/common.css">
+  </head>
+  <body>
+     <h1>JBoss Messaging Message Redistribution Example</h1>
+     <br>
+     <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, JBoss Messaging 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, JBoss Messaging 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>jbm-queues.xml</code> or <code>jbm-configuration.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>jbm-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>
+     <code>
+  &lt;address-settings match="jms.#"&gt;
+      &lt;redistribution-delay&gt;0&lt;/redistribution-delay&gt;
+   &lt;/address-settings&gt;
+   </code>
+     </pre>    
+     <p>For more information on JBoss Messaging 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>ant</code> from this directory</i></p>
+     <br>
+     <ol>
+        <li>Get an initial context for looking up JNDI from server 0</li>
+        <pre>
+           <code>
+   ic0 = getContext(0);
+   </code>
+        </pre>
+
+        <li>Look-up the JMS Queue object from JNDI</li>
+        <pre>
+           <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>
+           <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code>
+        </pre>
+
+        <li>Get an initial context for looking up JNDI from server 1.</li>
+        <pre>
+           <code>ic1 = getContext(1);</code>
+        </pre>
+
+        <li>Look-up a JMS Connection Factory object from JNDI on server 1</li>
+        <pre>
+           <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>
+          <code>
+   connection0 = cf0.createConnection();
+          </code>
+        </pre>
+        
+        <li>We create a JMS Connection connection1 which is a connection to server 1</li>
+        <pre>
+          <code>
+   connection1 = cf1.createConnection();
+          </code>
+        </pre>
+
+        <li>We create a JMS Session on server 0, note the session is CLIENT_ACKNOWLEDGE</li>
+        <pre>
+           <code>
+   Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+           </code>
+        </pre>
+        
+        <li>We create a JMS Session on server 1, note the session is CLIENT_ACKNOWLEDGE</li>
+        <pre>
+           <code>
+   Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            </code>
+        </pre>
+
+        <li>We start the connections to ensure delivery occurs on them</li>
+        <pre>
+           <code>
+   connection0.start();
+
+   connection1.start();
+           </code>
+        </pre>
+
+        <li>We create JMS MessageConsumer objects on server 0 and server 1</li>
+        <pre>
+           <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>
+           <code>
+   MessageProducer producer = session0.createProducer(queue);</code>
+        </pre>
+
+        <li>We send some messages to server 0.</li>
+        <pre>
+           <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.
+         JBoss Messaging has <b>load balanced</b> the messages between the available consumers on the different nodes.
+         JBoss Messaging 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>
+           <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>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 <b>do not</b> acknowledge the message consumed on node 1 yet.</li>
+        <pre>
+           <code>
+           message0.acknowledge();
+           </code>
+        </pre>
+        
+        <li>We now close the session and consumer on node 1. (Closing the session automatically closes the consumer)
+        </li>
+        <pre>
+           <code>session1.close();</code>
+        </pre>
+        
+        <li>Since there is no more consumer on node 1, the messages on node 1 are now stranded (no local consumers)
+        so JBoss Messaging will redistribute them to node 0 so they can be consumed. We consume them from
+        node 0.</li>
+        <pre>
+           <code>
+           for (int i = 0; i < numMessages; i += 2)
+         {
+            message0 = (TextMessage)consumer0.receive(5000);
+
+            System.out.println("Got message: " + message0.getText() + " from node 0");           
+         }
+           </code>
+        </pre> 
+        
+        <li>We ack the redistributed messages.</li>
+        <pre>
+           <code>message0.acknowledge();</code>
+        </pre>
+           
+        
+        <li>And finally (no pun intended), <b>always</b> remember to close your 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>
+           <code>
+	finally
+	{
+	      if (connection0 != null)
+         {
+            connection0.close();
+         }
+
+         if (connection1 != null)
+         {
+            connection1.close();
+         }
+
+         if (ic0 != null)
+         {
+            ic0.close();
+         }
+
+         if (ic1 != null)
+         {
+            ic1.close();
+         }
+	}
+           </code>
+        </pre>
+
+     </ol>
+  </body>
+</html>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server0/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server0/client-jndi.properties	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/queue-message-redistribution/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server0/jbm-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server0/jbm-configuration.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,52 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+   <configuration>
+
+      <clustered>true</clustered>
+
+      <!-- Connectors -->
+
+      <connector name="netty-connector">
+         <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+         <param key="jbm.remoting.netty.port" value="5445" type="Integer"/>
+      </connector>
+
+      <!-- Acceptors -->
+
+      <acceptor name="netty-acceptor">
+         <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+         <param key="jbm.remoting.netty.port" value="5445" type="Integer"/>
+      </acceptor>
+
+      <!-- Clustering configuration -->
+
+      <broadcast-group name="my-broadcast-group">
+         <group-address>231.7.7.7</group-address>
+         <group-port>9876</group-port>
+         <broadcast-period>100</broadcast-period>
+         <connector-ref connector-name="netty-connector"/>
+      </broadcast-group>
+
+      <discovery-group name="my-discovery-group">
+         <group-address>231.7.7.7</group-address>
+         <group-port>9876</group-port>
+         <refresh-timeout>10000</refresh-timeout>
+      </discovery-group>
+
+      <cluster-connection name="my-cluster">
+         <address>jms</address>
+         <retry-interval>500</retry-interval>
+         <use-duplicate-detection>true</use-duplicate-detection>
+         <forward-when-no-consumers>false</forward-when-no-consumers>
+         <max-hops>1</max-hops>
+         <discovery-group-ref discovery-group-name="my-discovery-group"/>
+      </cluster-connection>
+
+      <!-- Other config -->
+
+      <journal-min-files>2</journal-min-files>
+
+   </configuration>
+
+</deployment>

Added: trunk/examples/jms/queue-message-redistribution/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server0/jbm-jms.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server0/jbm-jms.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,18 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty-connector"/>
+      <entry name="ConnectionFactory"/>
+      <entry name="XAConnectionFactory"/>
+      <entry name="java:/ConnectionFactory"/>
+      <entry name="java:/XAConnectionFactory"/>
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server0/jbm-queues.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server0/jbm-queues.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,24 @@
+<settings xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+   <!--security for example queue-->
+   <security match="jms.queue.exampleQueue">
+      <permission type="createDurableQueue" roles="guest"/>
+      <permission type="deleteDurableQueue" roles="guest"/>
+      <permission type="createTempQueue" roles="guest"/>
+      <permission type="deleteTempQueue" roles="guest"/>
+      <permission type="consume" roles="guest"/>
+      <permission type="send" roles="guest"/>
+   </security>
+   
+   <!-- 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-settings match="jms.#">
+      <redistribution-delay>0</redistribution-delay>
+   </address-settings>
+
+</settings>

Added: trunk/examples/jms/queue-message-redistribution/server0/jbm-security.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server0/jbm-security.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server0/jbm-security.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-security.xsd ">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/server0/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server0/jbm-standalone-beans.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server0/jbm-standalone-beans.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">1099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">1098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+	<!-- The security manager -->
+   <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+	<!-- The core server -->
+   <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl"> 
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="JBMSecurityManager"/>
+         </parameter>        
+      </constructor>         
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="MessagingServer"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/server1/client-jndi.properties
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server1/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server1/client-jndi.properties	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:2099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/queue-message-redistribution/server1/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server1/jbm-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server1/jbm-configuration.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,52 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+   <configuration>
+
+      <clustered>true</clustered>
+
+      <!-- Connectors -->
+
+      <connector name="netty-connector">
+         <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+         <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+      </connector>
+
+      <!-- Acceptors -->
+
+      <acceptor name="netty-acceptor">
+         <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+         <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+      </acceptor>
+
+      <!-- Clustering configuration -->
+
+      <broadcast-group name="my-broadcast-group">
+         <group-address>231.7.7.7</group-address>
+         <group-port>9876</group-port>
+         <broadcast-period>100</broadcast-period>
+         <connector-ref connector-name="netty-connector"/>
+      </broadcast-group>
+
+      <discovery-group name="my-discovery-group">
+         <group-address>231.7.7.7</group-address>
+         <group-port>9876</group-port>
+         <refresh-timeout>10000</refresh-timeout>
+      </discovery-group>
+
+      <cluster-connection name="my-cluster">
+         <address>jms</address>
+         <retry-interval>500</retry-interval>
+         <use-duplicate-detection>true</use-duplicate-detection>
+         <forward-when-no-consumers>false</forward-when-no-consumers>
+         <max-hops>1</max-hops>
+         <discovery-group-ref discovery-group-name="my-discovery-group"/>
+      </cluster-connection>
+
+      <!-- Other config -->
+
+      <journal-min-files>2</journal-min-files>
+
+   </configuration>
+
+</deployment>

Added: trunk/examples/jms/queue-message-redistribution/server1/jbm-jms.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server1/jbm-jms.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server1/jbm-jms.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,18 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty-connector"/>
+      <entry name="ConnectionFactory"/>
+      <entry name="XAConnectionFactory"/>
+      <entry name="java:/ConnectionFactory"/>
+      <entry name="java:/XAConnectionFactory"/>
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/server1/jbm-queues.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server1/jbm-queues.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server1/jbm-queues.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,24 @@
+<settings xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+   <!--security for example queue-->
+   <security match="jms.queue.exampleQueue">
+      <permission type="createDurableQueue" roles="guest"/>
+      <permission type="deleteDurableQueue" roles="guest"/>
+      <permission type="createTempQueue" roles="guest"/>
+      <permission type="deleteTempQueue" roles="guest"/>
+      <permission type="consume" roles="guest"/>
+      <permission type="send" roles="guest"/>
+   </security>
+   
+   <!-- 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-settings match="jms.#">
+      <redistribution-delay>0</redistribution-delay>
+   </address-settings>
+
+</settings>

Added: trunk/examples/jms/queue-message-redistribution/server1/jbm-security.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server1/jbm-security.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server1/jbm-security.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-security.xsd ">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/server1/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/queue-message-redistribution/server1/jbm-standalone-beans.xml	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/server1/jbm-standalone-beans.xml	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">2099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">2098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+	<!-- The security manager -->
+   <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+	<!-- The core server -->
+   <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl"> 
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="JBMSecurityManager"/>
+         </parameter>        
+      </constructor>         
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="MessagingServer"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/queue-message-redistribution/src/org/jboss/jms/example/QueueMessageRedistributionExample.java
===================================================================
--- trunk/examples/jms/queue-message-redistribution/src/org/jboss/jms/example/QueueMessageRedistributionExample.java	                        (rev 0)
+++ trunk/examples/jms/queue-message-redistribution/src/org/jboss/jms/example/QueueMessageRedistributionExample.java	2009-04-14 16:28:56 UTC (rev 6423)
@@ -0,0 +1,184 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+package org.jboss.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 javax.naming.InitialContext;
+
+/**
+ * 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.
+ *
+ * @author <a href="tim.fox at jboss.com>Tim Fox</a>
+ */
+public class QueueMessageRedistributionExample extends JMSExample
+{
+   public static void main(String[] args)
+   {
+      new QueueMessageRedistributionExample().run(args);
+   }
+
+   public boolean runExample() throws Exception
+   {
+      Connection connection0 = null;
+
+      Connection connection1 = null;
+
+      InitialContext ic0 = null;
+
+      InitialContext ic1 = null;
+
+      try
+      {
+         // Step 1. Get an initial context for looking up JNDI from server 0
+         ic0 = getContext(0);
+
+         // 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
+         ic1 = getContext(1);
+
+         // Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
+         ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
+
+         // 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 JBoss Messaging 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();
+        
+         return true;
+      }
+      finally
+      {
+         // Step 18. Be sure to close our resources!
+
+         if (connection0 != null)
+         {
+            connection0.close();
+         }
+
+         if (connection1 != null)
+         {
+            connection1.close();
+         }
+
+         if (ic0 != null)
+         {
+            ic0.close();
+         }
+
+         if (ic1 != null)
+         {
+            ic1.close();
+         }
+      }
+   }
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/AddressSettingsDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/AddressSettingsDeployer.java	2009-04-14 16:28:02 UTC (rev 6422)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/AddressSettingsDeployer.java	2009-04-14 16:28:56 UTC (rev 6423)
@@ -23,6 +23,7 @@
 package org.jboss.messaging.core.deployers.impl;
 
 import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.AddressSettings;
 import org.jboss.messaging.utils.SimpleString;
@@ -35,6 +36,9 @@
  */
 public class AddressSettingsDeployer extends XmlDeployer
 {
+   private static final Logger log = Logger.getLogger(AddressSettingsDeployer.class);
+
+   
    private static final String DEAD_LETTER_ADDRESS_NODE_NAME = "dead-letter-address";
 
    private static final String EXPIRY_ADDRESS_NODE_NAME = "expiry-address";
@@ -54,6 +58,8 @@
    private static final String MESSAGE_COUNTER_HISTORY_DAY_LIMIT_NODE_NAME = "message-counter-history-day-limit";
 
    private static final String LVQ_NODE_NAME = "last-value-queue";
+   
+   private static final String REDISTRIBUTION_DELAY_NODE_NAME = "redistribution-delay";
 
    private final HierarchicalRepository<AddressSettings> addressSettingsRepository;
 
@@ -93,6 +99,7 @@
     */
    public void deploy(Node node) throws Exception
    {
+      log.info("** address setings deployer, deploying");
       String match = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue();
 
       NodeList children = node.getChildNodes();
@@ -145,6 +152,10 @@
          {
             addressSettings.setMaxDeliveryAttempts(Integer.valueOf(child.getTextContent().trim()));
          }
+         else if (REDISTRIBUTION_DELAY_NODE_NAME.equalsIgnoreCase(child.getNodeName()))
+         {           
+            addressSettings.setRedistributionDelay(Long.valueOf(child.getTextContent().trim()));
+         }
       }
 
       addressSettingsRepository.addMatch(match, addressSettings);

Modified: trunk/src/schemas/jbm-queues.xsd
===================================================================
--- trunk/src/schemas/jbm-queues.xsd	2009-04-14 16:28:02 UTC (rev 6422)
+++ trunk/src/schemas/jbm-queues.xsd	2009-04-14 16:28:56 UTC (rev 6423)
@@ -73,9 +73,12 @@
         <xsd:element name="message-counter-history-day-limit" type="xsd:positiveInteger"
             maxOccurs="1" minOccurs="0">
         </xsd:element>
-         <xsd:element name="solo-queue" type="xsd:boolean"
+        <xsd:element name="last-value-queue" type="xsd:boolean"
             maxOccurs="1" minOccurs="0">
         </xsd:element>
+        <xsd:element name="redistribution-delay" type="xsd:unsignedLong"
+            maxOccurs="1" minOccurs="0">
+        </xsd:element>
       </xsd:sequence>
    	<xsd:attribute name="match" type="xsd:string" use="required"></xsd:attribute>
    </xsd:complexType>   




More information about the jboss-cvs-commits mailing list