Need help understanding clustering
dspiess Jul 28, 2011 5:11 PMWe're trying to set up a HornetQ stand-alone symmetric cluster, and it's not behaving quite like we expected.
We have 4 nodes set up in our JMS queue cluster (A, B, C ,D). When we were using JNDI to look up server A, we can post messages to it and they get balanced across the four nodes. So if we sent 1000 messages, each would have 250 which is what we expected.
When we use JNDI to consume the messages like below, we have to run it 4 times to pull the messages.
initialContext = hornetConsumer.getContext(0); ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); Queue queue = (Queue)initialContext.lookup("/queue/Queue"); connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer messageConsumer = session.createConsumer(queue); connection.start(); while ((messageReceived = (TextMessage) messageConsumer.receive(5000)) != null) { // do stuff with message }
Each time we run this, we get 250 messages. This seems to make sense since we are connecting to server A, which is forwarding the connection to one server. Right?
We thought if we'd change the code to use the DiscoveryGroup to create a connection, we'd get all 1000 messages. We'd like to treat the cluster as one "super queue".
We changed our code to
DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration("231.7.7.7", 9876); ConnectionFactory cf = (ConnectionFactory)HornetQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF); Thread.sleep(2000); Queue queue = HornetQJMSClient.createQueue("Queue"); connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer messageConsumer = session.createConsumer(queue); connection.start(); while ((messageReceived = (TextMessage) messageConsumer.receive(5000)) != null) { // do stuff with message }
This pulled messages again from one queue at a time, but one queue was always ignored. Since we were using the DiscoveryGroup, we thought we'd be connecting to the queues as a group.
So I have the following questions:
1) Is the DiscoveryGroup code doing the same thing as the JNDI code, and just connecting to one server at time?
2) Why does the second code listing only hit three of the servers in the cluster for messages? If we post 1000 messages, we get 250 x 3 back.
3) Is there a way to pull from a queue cluster and get 1000 messages when we post 1000 messages?