[hornetq-commits] JBoss hornetq SVN: r10293 - in branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway: server0 and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 7 06:37:16 EST 2011


Author: ataylor
Date: 2011-03-07 06:37:16 -0500 (Mon, 07 Mar 2011)
New Revision: 10293

Modified:
   branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/readme.html
   branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml
   branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml
   branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java
Log:
fixed one way clustered example and wrote read me

Modified: branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/readme.html
===================================================================
--- branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/readme.html	2011-03-07 10:19:59 UTC (rev 10292)
+++ branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/readme.html	2011-03-07 11:37:16 UTC (rev 10293)
@@ -6,29 +6,35 @@
     <script type="text/javascript" src="../../common/prettify.js"></script>
   </head>
   <body onload="prettyPrint()">
-     <h1>JMS Load Balanced Static Clustered Queue Example</h1>
+     <h1>JMS Load Balanced Static Clustered One Way Queue Example</h1>
 
-     <p>This example demonstrates a JMS queue deployed on two different nodes. The two nodes are configured to form a cluster
-       from a <em>static</em> list of nodes.</p>
+     <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>both</b> consumers receive the sent messages
+     <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, HornetQ <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 cluster between the two nodes
-     and to load balance the messages between the nodes.</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;
+     <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;forward-when-no-consumers&gt;true&lt;/forward-when-no-consumers&gt;
-        &lt;max-hops&gt;1&lt;/max-hops&gt;
-        &lt;static-connectors>
-           &lt;connector-ref>server1-connector&lt;/connector-ref>
-        &lt;/static-connectors>
+        &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>    
@@ -47,37 +53,46 @@
 
         <li>Look-up the JMS Queue object from JNDI</li>
         <pre class="prettyprint">
-           <code>Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");</code>
+           <code>
+   Queue queue = (Queue)ic0.lookup("/queue/exampleQueue");
+           </code>
         </pre>
 
         <li>Look-up a JMS Connection Factory object from JNDI on server 0</li>
         <pre class="prettyprint">
-           <code>ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");</code>
+           <code>
+   ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("/ConnectionFactory");
+           </code>
         </pre>
 
-        <li>Get an initial context for looking up JNDI from server 1.</li>
+
+        <li>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</li>
         <pre class="prettyprint">
-           <code>ic1 = getContext(1);</code>
+           <code>
+   initialConnection = cf0.createConnection();
+           </code>
         </pre>
 
-        <li>Look-up a JMS Connection Factory object from JNDI on server 1</li>
+        <li>We create a JMS Connection connection0 which is a connection to server 0</li>
         <pre class="prettyprint">
-           <code>ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("/ConnectionFactory");
+           <code>
+   connection0 = cf0.createConnection()
            </code>
         </pre>
 
-        <li>We create a JMS Connection connection0 which is a connection to server 0</li>
+        <li>We create a JMS Connection connection0 which is a connection to server 1</li>
         <pre class="prettyprint">
-          <code>
-   connection0 = cf0.createConnection();
-          </code>
+           <code>
+   connection1 = cf0.createConnection()
+           </code>
         </pre>
-        
-        <li>We create a JMS Connection connection1 which is a connection to server 1</li>
+
+        <li>We create a JMS Connection connection0 which is a connection to server 2</li>
         <pre class="prettyprint">
-          <code>
-   connection1 = cf1.createConnection();
-          </code>
+           <code>
+   connection2 = cf0.createConnection()
+           </code>
         </pre>
 
         <li>We create a JMS Session on server 0</li>
@@ -94,34 +109,49 @@
             </code>
         </pre>
 
+        <li>We create a JMS Session on server 1</li>
+        <pre class="prettyprint">
+           <code>
+   Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            </code>
+        </pre>
         <li>We start the connections to ensure delivery occurs on them</li>
         <pre class="prettyprint">
            <code>
    connection0.start();
 
    connection1.start();
+
+   connection2.start();
            </code>
         </pre>
 
+
         <li>We create JMS MessageConsumer objects on server 0 and server 1</li>
         <pre class="prettyprint">
            <code>
    MessageConsumer consumer0 = session0.createConsumer(queue);
 
-   MessageConsumer consumer1 = session1.createConsumer(queue);
+   MessageConsumer consumer2 = session2.createConsumer(queue);
+
+   MessageConsumer consumer3 = session3.createConsumer(queue);
            </code>
         </pre>
 
+
         <li>We create a JMS MessageProducer object on server 0.</li>
         <pre class="prettyprint">
            <code>
-   MessageProducer producer = session0.createProducer(queue);</code>
+   Session sendSession = getServerConnection(0, connection0, connection1, connection2).createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+   MessageProducer producer = sendSession.createProducer(queue);
+           </code>
         </pre>
 
         <li>We send some messages to server 0.</li>
         <pre class="prettyprint">
            <code>
-	final int numMessages = 10;
+	final int numMessages = 18;
 
 	for (int i = 0; i < numMessages; i++)
 	{
@@ -152,6 +182,10 @@
 	   TextMessage message1 = (TextMessage)consumer1.receive(5000);
 	
 	   System.out.println("Got message: " + message1.getText() + " from node 1");
+
+      TextMessage message2 = (TextMessage)consumer2.receive(5000);
+
+      System.out.println("Got message: " + message2.getText() + " from node " + con2Node);
 	}
            </code>
         </pre> 
@@ -162,15 +196,30 @@
            <code>
 	finally
 	{
-	   if (connection0 != null)
-	   {
-	      connection0.close();
-	   }
-	      
-	   if (connection1 != null)
-	   {
-	      connection1.close();
-	   }
+      if (initialConnection != null)
+      {
+         initialConnection.close();
+      }
+
+      if (connection0 != null)
+      {
+         connection0.close();
+      }
+
+      if (connection1 != null)
+      {
+         connection1.close();
+      }
+
+      if (connection2 != null)
+      {
+         connection2.close();
+      }
+
+      if (ic0 != null)
+      {
+         ic0.close();
+      }
 	}
            </code>
         </pre>

Modified: branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml
===================================================================
--- branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml	2011-03-07 10:19:59 UTC (rev 10292)
+++ branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml	2011-03-07 11:37:16 UTC (rev 10293)
@@ -45,7 +45,7 @@
          <retry-interval>500</retry-interval>
          <use-duplicate-detection>true</use-duplicate-detection>
          <forward-when-no-consumers>true</forward-when-no-consumers>
-         <max-hops>1</max-hops>
+         <max-hops>2</max-hops>
          <static-connectors allow-direct-connections-only="true">
             <connector-ref>server1-connector</connector-ref>
          </static-connectors>

Modified: branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml
===================================================================
--- branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml	2011-03-07 10:19:59 UTC (rev 10292)
+++ branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml	2011-03-07 11:37:16 UTC (rev 10293)
@@ -45,7 +45,7 @@
          <retry-interval>500</retry-interval>
          <use-duplicate-detection>true</use-duplicate-detection>
          <forward-when-no-consumers>true</forward-when-no-consumers>
-         <max-hops>1</max-hops>
+         <max-hops>2</max-hops>
          <static-connectors allow-direct-connections-only="true">
             <connector-ref>server2-connector</connector-ref>
          </static-connectors>

Modified: branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java
===================================================================
--- branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java	2011-03-07 10:19:59 UTC (rev 10292)
+++ branches/Branch_2_2_EAP/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java	2011-03-07 11:37:16 UTC (rev 10293)
@@ -42,8 +42,6 @@
 
       Connection connection2 = null;
 
-      Connection connection3 = null;
-
       InitialContext ic0 = null;
       Thread.sleep(5000);
       try
@@ -94,13 +92,28 @@
 
          MessageConsumer consumer2 = session2.createConsumer(queue);
 
-         Thread.sleep(2000);
+         Thread.sleep(4000);
 
-         // Step 13. We create a JMS MessageProducer object on server 2
-         MessageProducer producer = session2.createProducer(queue);
+         int con0Node = getServer(connection0);
+         int con1Node = getServer(connection1);
+         int con2Node = getServer(connection2);
 
-         // Step 14. We send some messages to server 2
+         System.out.println("con0Node = " + con0Node);
+         System.out.println("con1Node = " + con1Node);
+         System.out.println("con2Node = " + con2Node);
 
+         if(con0Node + con1Node + con2Node != 3)
+         {
+            System.out.println("connections not load balanced");
+            return false;
+         }
+         // Step 13. We create a JMS MessageProducer object on server 0
+         Session sendSession = 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++)
@@ -112,22 +125,11 @@
             System.out.println("Sent message: " + message.getText());
          }
          Thread.sleep(2000);
-         // Step 15. We now consume those messages on *both* server 0,server 1 and 3.
+         // 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
-         int con0Node = getServer(connection0);
-         int con1Node = getServer(connection1);
-         int con2Node = getServer(connection2);
 
-         if(con0Node + con1Node + con2Node != 3)
-         {
-            System.out.println("connections not load balanced");
-            System.out.println("con0Node = " + con0Node);
-            System.out.println("con1Node = " + con1Node);
-            System.out.println("con2Node = " + con2Node);
-            return false;
-         }
          for (int i = 0; i < numMessages; i += 3)
          {
             TextMessage message0 = (TextMessage)consumer0.receive(5000);
@@ -141,7 +143,6 @@
             TextMessage message2 = (TextMessage)consumer2.receive(5000);
 
             System.out.println("Got message: " + message2.getText() + " from node " + con2Node);
-            System.out.println("i = " + i);
          }
 
          return true;
@@ -170,11 +171,6 @@
             connection2.close();
          }
 
-         if (connection3 != null)
-         {
-            connection3.close();
-         }
-
          if (ic0 != null)
          {
             ic0.close();



More information about the hornetq-commits mailing list