[jboss-user] [JBoss Messaging] - Re: Clustered server preference

chip_schoch do-not-reply at jboss.com
Wed Apr 16 12:17:32 EDT 2008


That was Chapter 3.1 and Chapter 1.2.2 respectively.  Here is the link http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/userguide-1.3.0.GA/html/c_overview.html

It looks like it was the 1.3 UserGuide.  I did initially set this stuff up last year.  It is only now that I have begun taking a closer look at how the load balancing is working.  

To that end I have written a test program based in the distributed queue example.  It posts 50 messages to a distributed queue then creates 2 listeners and consumes the messages.  I was suprised to see that the message consumption was so random.  I would have expected FIFO consumption.  I tried setting DefaultPreserveOrdering=true but that caused all the message to be consumed by one listener.  Essentially, it defeated load balancing.  Is there a way to get FIFO consumption and load balancing?  The Random House Unabridged dictionary defines Queue As:

anonymous wrote : 3.	Computers. a FIFO-organized sequence of items, as data, messages, jobs, or the like, waiting for action.

Below is my test log output.

  | [2008-04-16 11:41:11,249] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_0 
  | [2008-04-16 11:41:11,311] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_1 
  | [2008-04-16 11:41:11,327] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_2 
  | [2008-04-16 11:41:11,343] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_3 
  | [2008-04-16 11:41:11,358] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_4 
  | [2008-04-16 11:41:11,374] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_5 
  | [2008-04-16 11:41:11,390] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_6 
  | [2008-04-16 11:41:11,405] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_7 
  | [2008-04-16 11:41:11,421] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_8 
  | [2008-04-16 11:41:11,436] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_9 
  | [2008-04-16 11:41:11,452] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_10 
  | [2008-04-16 11:41:11,468] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_11 
  | [2008-04-16 11:41:11,483] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_12 
  | [2008-04-16 11:41:11,499] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_13 
  | [2008-04-16 11:41:11,515] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_14 
  | [2008-04-16 11:41:11,530] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_15 
  | [2008-04-16 11:41:11,546] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_16 
  | [2008-04-16 11:41:11,561] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_17 
  | [2008-04-16 11:41:11,577] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_18 
  | [2008-04-16 11:41:11,593] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_19 
  | [2008-04-16 11:41:11,608] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_20 
  | [2008-04-16 11:41:11,624] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_21 
  | [2008-04-16 11:41:11,655] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_22 
  | [2008-04-16 11:41:11,671] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_23 
  | [2008-04-16 11:41:11,686] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_24 
  | [2008-04-16 11:41:11,702] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_25 
  | [2008-04-16 11:41:11,718] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_26 
  | [2008-04-16 11:41:11,733] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_27 
  | [2008-04-16 11:41:11,749] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_28 
  | [2008-04-16 11:41:11,765] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_29 
  | [2008-04-16 11:41:11,780] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_30 
  | [2008-04-16 11:41:11,796] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_31 
  | [2008-04-16 11:41:11,811] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_32 
  | [2008-04-16 11:41:11,811] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_33 
  | [2008-04-16 11:41:11,843] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_34 
  | [2008-04-16 11:41:11,843] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_35 
  | [2008-04-16 11:41:11,874] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_36 
  | [2008-04-16 11:41:11,874] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_37 
  | [2008-04-16 11:41:11,890] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_38 
  | [2008-04-16 11:41:11,905] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_39 
  | [2008-04-16 11:41:11,921] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_40 
  | [2008-04-16 11:41:11,936] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_41 
  | [2008-04-16 11:41:11,952] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_42 
  | [2008-04-16 11:41:11,968] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_43 
  | [2008-04-16 11:41:12,015] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_44 
  | [2008-04-16 11:41:12,046] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_45 
  | [2008-04-16 11:41:12,061] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_46 
  | [2008-04-16 11:41:12,077] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_47 
  | [2008-04-16 11:41:12,093] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_48 
  | [2008-04-16 11:41:12,093] INFO  - com.eLynx.Utility.test.JBMTest - Queueing message: Test_Message_49 
  | [2008-04-16 11:41:12,389] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_0 
  | [2008-04-16 11:41:12,593] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_1 
  | [2008-04-16 11:41:13,624] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_19 
  | [2008-04-16 11:41:13,983] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_20 
  | [2008-04-16 11:41:14,749] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_37 
  | [2008-04-16 11:41:15,233] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_42 
  | [2008-04-16 11:41:15,842] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_8 
  | [2008-04-16 11:41:16,358] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_16 
  | [2008-04-16 11:41:16,936] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_28 
  | [2008-04-16 11:41:17,452] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_36 
  | [2008-04-16 11:41:17,999] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_48 
  | [2008-04-16 11:41:18,592] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_9 
  | [2008-04-16 11:41:19,139] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_21 
  | [2008-04-16 11:41:19,639] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_31 
  | [2008-04-16 11:41:20,202] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_43 
  | [2008-04-16 11:41:20,717] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_4 
  | [2008-04-16 11:41:21,311] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_15 
  | [2008-04-16 11:41:21,811] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_26 
  | [2008-04-16 11:41:22,405] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_41 
  | [2008-04-16 11:41:22,905] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_5 
  | [2008-04-16 11:41:23,577] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_22 
  | [2008-04-16 11:41:24,155] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_34 
  | [2008-04-16 11:41:24,639] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_47 
  | [2008-04-16 11:41:25,373] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_14 
  | [2008-04-16 11:41:25,780] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_30 
  | [2008-04-16 11:41:26,576] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_6 
  | [2008-04-16 11:41:27,030] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_17 
  | [2008-04-16 11:41:27,686] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_39 
  | [2008-04-16 11:41:28,092] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_3 
  | [2008-04-16 11:41:28,858] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_29 
  | [2008-04-16 11:41:29,358] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_46 
  | [2008-04-16 11:41:30,029] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_25 
  | [2008-04-16 11:41:30,561] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_45 
  | [2008-04-16 11:41:31,295] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_27 
  | [2008-04-16 11:41:31,795] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_2 
  | [2008-04-16 11:41:32,561] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_38 
  | [2008-04-16 11:41:32,904] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_13 
  | [2008-04-16 11:41:33,654] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_10 
  | [2008-04-16 11:41:33,998] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_32 
  | [2008-04-16 11:41:34,795] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_24 
  | [2008-04-16 11:41:35,357] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_44 
  | [2008-04-16 11:41:36,014] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_23 
  | [2008-04-16 11:41:36,435] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_11 
  | [2008-04-16 11:41:37,123] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_18 
  | [2008-04-16 11:41:37,560] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_33 
  | [2008-04-16 11:41:38,326] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_7 
  | [2008-04-16 11:41:38,701] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_35 
  | [2008-04-16 11:41:39,435] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_49 
  | [2008-04-16 11:41:39,763] INFO  - com.eLynx.Utility.test.TestListener - Listener_1 received message: Test_Message_40 
  | [2008-04-16 11:41:40,529] INFO  - com.eLynx.Utility.test.TestListener - Listener_2 received message: Test_Message_12 
  | 
  | 
  | For completeness here is the program that produced this output:
  | 
  | package com.eLynx.Utility.test;
  |   | 
  |   | 
  |   | 
  |   | import java.util.Properties;
  |   | 
  |   | import javax.jms.Connection;
  |   | import javax.jms.ConnectionFactory;
  |   | import javax.jms.JMSException;
  |   | import javax.jms.Message;
  |   | import javax.jms.MessageConsumer;
  |   | import javax.jms.MessageListener;
  |   | import javax.jms.MessageProducer;
  |   | import javax.jms.Queue;
  |   | import javax.jms.QueueSession;
  |   | import javax.jms.Session;
  |   | import javax.jms.TextMessage;
  |   | 
  |   | import javax.naming.Context;
  |   | import javax.naming.InitialContext;
  |   | import javax.naming.NamingException;
  |   | 
  |   | import org.apache.log4j.Logger;
  |   | 
  |   | /**
  |   |  * Class JBMTest
  |   |  */
  |   | 
  |   | public class JBMTest
  |   | {
  |   |     static Logger logger                   = Logger.getLogger (JBMTest.class);
  |   |     static MessageProducer m_producer      = null;
  |   |     static Queue m_producerQueue           = null;
  |   |     static Connection m_jmsConnection      = null;
  |   |     static QueueSession m_jmsSession       = null;
  |   |     static InitialContext m_initialContext_1 = null;
  |   |     static InitialContext m_initialContext_2 = null;
  |   |     static ConnectionFactory m_factory_1     = null;
  |   |     static ConnectionFactory m_factory_2     = null;
  |   | 
  |   |     /**
  |   |      * Method: initialize
  |   |      *
  |   |      *
  |   |      * @throws NamingException
  |   |      */
  |   | 
  |   |     static void initialize () throws NamingException
  |   |     {
  |   |         Properties p = new Properties ();
  |   |         p.put (Context.PROVIDER_URL, "jnp://devapp1.qa.cin.int:1100");
  |   |         p.put (Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  |   |         p.put (Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
  |   | 
  |   |         m_initialContext_1 = new InitialContext (p);
  |   |         m_factory_1        = (ConnectionFactory) m_initialContext_1.lookup ("/LoadBalanceConnectionFactory");
  |   | 
  |   |     
  |   |         p.put (Context.PROVIDER_URL, "jnp://devapp2.qa.cin.int:1100");
  |   |         m_initialContext_2 = new InitialContext (p);
  |   |         m_factory_2        = (ConnectionFactory) m_initialContext_2.lookup ("/LoadBalanceConnectionFactory");
  |   |     }
  |   | 
  |   |     /**
  |   |      * Method: main
  |   |      *
  |   |      *
  |   |      * @param args
  |   |      */
  |   | 
  |   |     public static void main (String[] args)
  |   |     {
  |   |         JBMTest tester = null;
  |   |         try
  |   |         {
  |   |             initialize ();
  |   | 
  |   |             tester = new JBMTest ();
  |   |             tester.sendMessages (50);
  |   |             tester.consumeMessages (50);
  |   | 
  |   |         }
  |   |         catch (Exception e)
  |   |         {
  |   |             logger.error (e.getMessage (), e);
  |   |         }
  |   |         finally
  |   |         {
  |   |             try
  |   |             {
  |   |                 if (tester != null)
  |   |                     tester.cleanup ();
  |   |             }
  |   |             catch (Exception e)
  |   |             {
  |   |                 logger.error ("Tester cleanup exception", e);
  |   |             }
  |   |         }
  |   |     }
  |   | 
  |   |     /**
  |   |      * Method: cleanup
  |   |      *
  |   |      *
  |   |      * @throws JMSException
  |   |      */
  |   | 
  |   |     void cleanup () throws JMSException
  |   |     {
  |   |         if (m_producer != null)
  |   |             m_producer.close ();
  |   |         if (m_jmsSession != null)
  |   |             m_jmsSession.close ();
  |   |         if (m_jmsConnection != null)
  |   |             m_jmsConnection.close ();
  |   |     }
  |   | 
  |   |     /**
  |   |      * Method: consumeMessages
  |   |      *
  |   |      *
  |   |      * @param count
  |   |      */
  |   | 
  |   |     void consumeMessages (int count)
  |   |     {
  |   |         TestListener listener1 = null;
  |   |         TestListener listener2 = null;
  |   | 
  |   |         try
  |   |         {
  |   |             listener1 = new TestListener ("Listener_1", m_initialContext_1, m_factory_1);
  |   |             listener2 = new TestListener ("Listener_2", m_initialContext_2, m_factory_2);
  |   |             listener1.m_jmsConnection.start ();
  |   |             listener2.m_jmsConnection.start ();
  |   | 
  |   |             int consumedCount = listener1.m_count + listener2.m_count;
  |   | 
  |   |             while (consumedCount < count)
  |   |             {
  |   |                 Thread.sleep (1000);
  |   |             }
  |   |         }
  |   |         catch (Exception e)
  |   |         {
  |   |             logger.error (e.getMessage (), e);
  |   |         }
  |   |         finally
  |   |         {
  |   |             try
  |   |             {
  |   |                 if (listener1 != null)
  |   |                     listener1.cleanup ();
  |   | 
  |   |                 if (listener2 != null)
  |   |                     listener2.cleanup ();
  |   |             }
  |   |             catch (Exception e)
  |   |             {
  |   |                 logger.error ("Cleanup exception", e);
  |   |             }
  |   |         }
  |   |     }
  |   | 
  |   |     /**
  |   |      * Method: sendMessages
  |   |      *
  |   |      *
  |   |      * @param count
  |   |      */
  |   | 
  |   |     void sendMessages (int count)
  |   |     {
  |   |         try
  |   |         {
  |   |             m_jmsConnection = m_factory_1.createConnection ();
  |   | 
  |   |             m_producerQueue = (Queue) m_initialContext_1.lookup ("/queue/testDistributedQueue");
  |   |             m_jmsConnection = m_factory_1.createConnection ();
  |   |             m_jmsSession    = (QueueSession) m_jmsConnection.createSession (false, Session.AUTO_ACKNOWLEDGE);
  |   |             m_producer      = m_jmsSession.createProducer (m_producerQueue);
  |   | 
  |   |             for (int i = 0; i < count; i++)
  |   |             {
  |   |                 logger.info ("Queueing message: Test_Message_" + i);
  |   |                 TextMessage tm = m_jmsSession.createTextMessage ("Test_Message_" + i);
  |   |                 m_producer.send (tm);
  |   |             }
  |   |         }
  |   |         catch (Exception e)
  |   |         {
  |   |             logger.error (e.getMessage (), e);
  |   |         }
  |   |     }
  |   | }
  |   | 
  |   | /**
  |   |  * Class TestListener
  |   |  */
  |   | 
  |   | class TestListener implements MessageListener
  |   | {
  |   |     static Logger logger       = Logger.getLogger (TestListener.class);
  |   |     int m_count                = 0;
  |   |     MessageConsumer m_consumer = null;
  |   |     Queue m_responseQueue      = null;
  |   |     Connection m_jmsConnection = null;
  |   |     QueueSession m_jmsSession  = null;
  |   |     String m_name              = null;
  |   | 
  |   |     /**
  |   |      * Constructor: TestListener
  |   |      *
  |   |      *
  |   |      * @param name
  |   |      * @param ic
  |   |      * @param factory
  |   |      *
  |   |      * @throws JMSException
  |   |      * @throws NamingException
  |   |      */
  |   | 
  |   |     TestListener (String name,
  |   |                   InitialContext ic,
  |   |                   ConnectionFactory factory) throws NamingException, JMSException
  |   |     {
  |   |         m_responseQueue = (Queue) ic.lookup ("/queue/testDistributedQueue");
  |   |         m_jmsConnection = factory.createConnection ();
  |   |         m_jmsSession    = (QueueSession) m_jmsConnection.createSession (false, Session.AUTO_ACKNOWLEDGE);
  |   |         m_consumer      = m_jmsSession.createConsumer (m_responseQueue);
  |   |         m_consumer.setMessageListener (this);
  |   |         m_name = name;
  |   |     }
  |   | 
  |   |     /**
  |   |      * Method: cleanup
  |   |      *
  |   |      *
  |   |      * @throws JMSException
  |   |      */
  |   | 
  |   |     void cleanup () throws JMSException
  |   |     {
  |   |         if (m_consumer != null)
  |   |             m_consumer.close ();
  |   |         if (m_jmsSession != null)
  |   |             m_jmsSession.close ();
  |   |         if (m_jmsConnection != null)
  |   |             m_jmsConnection.close ();
  |   |     }
  |   | 
  |   |     /**
  |   |      * Method: onMessage
  |   |      *
  |   |      *
  |   |      * @param arg0
  |   |      */
  |   | 
  |   |     public void onMessage (Message arg0)
  |   |     {
  |   |         try
  |   |         {
  |   |             TextMessage msg = (TextMessage) arg0;
  |   |             logger.info (m_name + " received message: " + msg.getText ());
  |   |             Thread.sleep (1000);
  |   |             m_count++;
  |   |         }
  |   |         catch (Exception e)
  |   |         {
  |   |             logger.error ("Exception", e);
  |   |         }
  |   |     }
  |   | }
  |   | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4144556#4144556

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4144556



More information about the jboss-user mailing list