[hornetq-commits] JBoss hornetq SVN: r9957 - in trunk/examples/jms/multiple-failover: server1 and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 1 05:57:45 EST 2010


Author: ataylor
Date: 2010-12-01 05:57:45 -0500 (Wed, 01 Dec 2010)
New Revision: 9957

Modified:
   trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml
   trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml
   trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml
   trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java
Log:
fixed example

Modified: trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml	2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml	2010-12-01 10:57:45 UTC (rev 9957)
@@ -26,7 +26,7 @@
 		<broadcast-group name="bg-group1">
 			<group-address>231.7.7.7</group-address>
 			<group-port>9876</group-port>
-			<broadcast-period>5000</broadcast-period>
+			<broadcast-period>1000</broadcast-period>
          <connector-ref>netty-connector</connector-ref>
 		</broadcast-group>
 	</broadcast-groups>

Modified: trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml	2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml	2010-12-01 10:57:45 UTC (rev 9957)
@@ -29,7 +29,7 @@
 		<broadcast-group name="bg-group1">
 			<group-address>231.7.7.7</group-address>
 			<group-port>9876</group-port>
-			<broadcast-period>5000</broadcast-period>
+			<broadcast-period>1000</broadcast-period>
          <connector-ref>netty-connector</connector-ref>
 		</broadcast-group>
 	</broadcast-groups>

Modified: trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml	2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml	2010-12-01 10:57:45 UTC (rev 9957)
@@ -41,7 +41,7 @@
 		<broadcast-group name="bg-group1">
 			<group-address>231.7.7.7</group-address>
 			<group-port>9876</group-port>
-			<broadcast-period>5000</broadcast-period>
+			<broadcast-period>1000</broadcast-period>
          <connector-ref>netty-connector</connector-ref>
 		</broadcast-group>
 	</broadcast-groups>

Modified: trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java
===================================================================
--- trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java	2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java	2010-12-01 10:57:45 UTC (rev 9957)
@@ -23,7 +23,11 @@
 import javax.jms.TextMessage;
 import javax.naming.InitialContext;
 
+import org.hornetq.api.core.TransportConfiguration;
 import org.hornetq.common.example.HornetQExample;
+import org.hornetq.core.client.impl.ClientSessionImpl;
+import org.hornetq.core.client.impl.DelegatingSession;
+import org.hornetq.jms.client.HornetQConnection;
 
 /**
  * @author <a href="mailto:andy.taylor at jboss.com">Andy Taylor</a>
@@ -40,7 +44,6 @@
    @Override
    public boolean runExample() throws Exception
    {
-      Thread.sleep(10000);
       final int numMessages = 30;
 
       Connection connection = null;
@@ -95,6 +98,7 @@
 
          // Step 10. Crash server #1, the live server, and wait a little while to make sure
          // it has really crashed
+         Thread.sleep(2000);
          killServer(0);
 
          // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
@@ -108,14 +112,36 @@
             System.err.println("Got exception while acknowledging message: " + e.getMessage());
          }
 
-         // Step 12. Consume again the 2nd half of the messages again. Note that they are not considered as redelivered.
-         for (int i = numMessages / 3; i < numMessages; i++)
+         // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+         for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
          {
             message0 = (TextMessage)consumer.receive(5000);
             System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
          }
          message0.acknowledge();
 
+         Thread.sleep(2000);
+         killServer(getServer(connection));
+
+         // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
+         // backup server has occurred
+         try
+         {
+            message0.acknowledge();
+         }
+         catch (JMSException e)
+         {
+            System.err.println("Got exception while acknowledging message: " + e.getMessage());
+         }
+
+         // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+         for (int i = (numMessages / 3) * 2; i < numMessages; i++)
+         {
+            message0 = (TextMessage)consumer.receive(5000);
+            System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
+         }
+         message0.acknowledge();
+
          return true;
       }
       finally
@@ -133,4 +159,12 @@
          }
       }
    }
+
+   private int getServer(Connection connection)
+   {
+      DelegatingSession session = (DelegatingSession) ((HornetQConnection) connection).getInitialSession();
+      TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration();
+      String port = (String) transportConfiguration.getParams().get("port");
+      return Integer.valueOf(port) - 5445;
+   }
 }



More information about the hornetq-commits mailing list