[hornetq-commits] JBoss hornetq SVN: r10028 - in trunk/examples/jms: clustered-static-oneway and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 9 13:29:14 EST 2010
Author: ataylor
Date: 2010-12-09 13:29:12 -0500 (Thu, 09 Dec 2010)
New Revision: 10028
Added:
trunk/examples/jms/clustered-static-oneway/
trunk/examples/jms/clustered-static-oneway/build.bat
trunk/examples/jms/clustered-static-oneway/build.sh
trunk/examples/jms/clustered-static-oneway/build.xml
trunk/examples/jms/clustered-static-oneway/readme.html
trunk/examples/jms/clustered-static-oneway/server0/
trunk/examples/jms/clustered-static-oneway/server0/client-jndi.properties
trunk/examples/jms/clustered-static-oneway/server0/hornetq-beans.xml
trunk/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml
trunk/examples/jms/clustered-static-oneway/server0/hornetq-jms.xml
trunk/examples/jms/clustered-static-oneway/server0/hornetq-users.xml
trunk/examples/jms/clustered-static-oneway/server0/jndi.properties
trunk/examples/jms/clustered-static-oneway/server1/
trunk/examples/jms/clustered-static-oneway/server1/client-jndi.properties
trunk/examples/jms/clustered-static-oneway/server1/hornetq-beans.xml
trunk/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml
trunk/examples/jms/clustered-static-oneway/server1/hornetq-jms.xml
trunk/examples/jms/clustered-static-oneway/server1/hornetq-users.xml
trunk/examples/jms/clustered-static-oneway/server1/jndi.properties
trunk/examples/jms/clustered-static-oneway/server2/
trunk/examples/jms/clustered-static-oneway/server2/client-jndi.properties
trunk/examples/jms/clustered-static-oneway/server2/hornetq-beans.xml
trunk/examples/jms/clustered-static-oneway/server2/hornetq-configuration.xml
trunk/examples/jms/clustered-static-oneway/server2/hornetq-jms.xml
trunk/examples/jms/clustered-static-oneway/server2/hornetq-users.xml
trunk/examples/jms/clustered-static-oneway/server2/jndi.properties
trunk/examples/jms/clustered-static-oneway/src/
trunk/examples/jms/clustered-static-oneway/src/org/
trunk/examples/jms/clustered-static-oneway/src/org/hornetq/
trunk/examples/jms/clustered-static-oneway/src/org/hornetq/jms/
trunk/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/
trunk/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java
Log:
added static one way cluster example
Added: trunk/examples/jms/clustered-static-oneway/build.bat
===================================================================
--- trunk/examples/jms/clustered-static-oneway/build.bat (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/build.bat 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,13 @@
+ at echo off
+
+set "OVERRIDE_ANT_HOME=..\..\..\tools\ant"
+
+if exist "..\..\..\src\bin\build.bat" (
+ rem running from TRUNK
+ call ..\..\..\src\bin\build.bat %*
+) else (
+ rem running from the distro
+ call ..\..\..\bin\build.bat %*
+)
+
+set "OVERRIDE_ANT_HOME="
Added: trunk/examples/jms/clustered-static-oneway/build.sh
===================================================================
--- trunk/examples/jms/clustered-static-oneway/build.sh (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/build.sh 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+OVERRIDE_ANT_HOME=../../../tools/ant
+export OVERRIDE_ANT_HOME
+
+if [ -f "../../../src/bin/build.sh" ]; then
+ # running from TRUNK
+ ../../../src/bin/build.sh "$@"
+else
+ # running from the distro
+ ../../../bin/build.sh "$@"
+fi
+
+
+
Property changes on: trunk/examples/jms/clustered-static-oneway/build.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/jms/clustered-static-oneway/build.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/build.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/build.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+<project default="run" name="HornetQ JMS Static Clustered Queue Example">
+
+ <import file="../../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.hornetq.jms.example.ClusterStaticOnewayExample"/>
+ <param name="hornetq.example.beans.file" value="server0 server1 server2"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.hornetq.jms.example.ClusterStaticOnewayExample"/>
+ <param name="hornetq.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
Added: trunk/examples/jms/clustered-static-oneway/readme.html
===================================================================
--- trunk/examples/jms/clustered-static-oneway/readme.html (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/readme.html 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,180 @@
+<html>
+ <head>
+ <title>HornetQ JMS Load Balanced Static Clustered Queue Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css" />
+ <link rel="stylesheet" type="text/css" href="../../common/prettify.css" />
+ <script type="text/javascript" src="../../common/prettify.js"></script>
+ </head>
+ <body onload="prettyPrint()">
+ <h1>JMS Load Balanced Static Clustered 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>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
+ 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>
+ <pre class="prettyprint">
+ <code><cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <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>
+ <static-connectors>
+ <connector-ref>server1-connector</connector-ref>
+ </static-connectors>
+ </cluster-connection>
+ </code>
+ </pre>
+ <p>For more information on HornetQ 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>./build.sh</code> (or <code>build.bat</code> on windows) from this directory</i></p>
+
+ <ol>
+ <li> Get an initial context for looking up JNDI from server 0.</li>
+ <pre class="prettyprint">
+ <code>
+ ic0 = getContext(0);
+ </code>
+ </pre>
+
+ <li>Look-up the JMS Queue object from JNDI</li>
+ <pre class="prettyprint">
+ <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>
+ </pre>
+
+ <li>Get an initial context for looking up JNDI from server 1.</li>
+ <pre class="prettyprint">
+ <code>ic1 = getContext(1);</code>
+ </pre>
+
+ <li>Look-up a JMS Connection Factory object from JNDI on server 1</li>
+ <pre class="prettyprint">
+ <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 class="prettyprint">
+ <code>
+ connection0 = cf0.createConnection();
+ </code>
+ </pre>
+
+ <li>We create a JMS Connection connection1 which is a connection to server 1</li>
+ <pre class="prettyprint">
+ <code>
+ connection1 = cf1.createConnection();
+ </code>
+ </pre>
+
+ <li>We create a JMS Session on server 0</li>
+ <pre class="prettyprint">
+ <code>
+ Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ </code>
+ </pre>
+
+ <li>We create a JMS Session on server 1</li>
+ <pre class="prettyprint">
+ <code>
+ Session session1 = connection1.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();
+ </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);
+ </code>
+ </pre>
+
+ <li>We create a JMS MessageProducer object on server 0.</li>
+ <pre class="prettyprint">
+ <code>
+ MessageProducer producer = session0.createProducer(queue);</code>
+ </pre>
+
+ <li>We send some messages to server 0.</li>
+ <pre class="prettyprint">
+ <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.
+ HornetQ has <b>load balanced</b> the messages between the available consumers on the different nodes.
+ HornetQ 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 class="prettyprint">
+ <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>And finally (no pun intended), <b>always</b> remember to close your JMS 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 class="prettyprint">
+ <code>
+ finally
+ {
+ if (connection0 != null)
+ {
+ connection0.close();
+ }
+
+ if (connection1 != null)
+ {
+ connection1.close();
+ }
+ }
+ </code>
+ </pre>
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server0/client-jndi.properties (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server0/client-jndi.properties 2010-12-09 18:29:12 UTC (rev 10028)
@@ -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/clustered-static-oneway/server0/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server0/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server0/hornetq-beans.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<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.hornetq.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="HornetQSecurityManager"/>
+ </parameter>
+ </constructor>
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="HornetQServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+
+</deployment>
Added: trunk/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server0/hornetq-configuration.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,69 @@
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+ <clustered>true</clustered>
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5445"/>
+ </connector>
+ <!-- connector to the server1 -->
+ <connector name="server1-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5446"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ <param key="port" value="5445"/>
+ </acceptor>
+ </acceptors>
+
+ <cluster-connections>
+ <cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <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>
+ <static-connectors allow-direct-connections-only="true">
+ <connector-ref>server1-connector</connector-ref>
+ </static-connectors>
+ </cluster-connection>
+ </cluster-connections>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createNonDurableQueue" roles="guest"/>
+ <permission type="deleteNonDurableQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server0/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server0/hornetq-jms.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,31 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="netty-connector"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+
+ <ha>true</ha>
+ <!-- Pause 1 second between connect attempts -->
+ <retry-interval>1000</retry-interval>
+
+ <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+ implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+ pause is the same length -->
+ <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+ <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+ <reconnect-attempts>-1</reconnect-attempts>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server0/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server0/hornetq-users.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server0/jndi.properties
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server0/jndi.properties (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server0/jndi.properties 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server1/client-jndi.properties
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server1/client-jndi.properties (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server1/client-jndi.properties 2010-12-09 18:29:12 UTC (rev 10028)
@@ -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/clustered-static-oneway/server1/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server1/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server1/hornetq-beans.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<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.hornetq.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="HornetQSecurityManager"/>
+ </parameter>
+ </constructor>
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="HornetQServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server1/hornetq-configuration.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,69 @@
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+ <clustered>true</clustered>
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5446"/>
+ </connector>
+ <!-- connector to the server0 -->
+ <connector name="server2-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5447"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ <param key="port" value="5446"/>
+ </acceptor>
+ </acceptors>
+
+ <!-- Clustering configuration -->
+ <cluster-connections>
+ <cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <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>
+ <static-connectors allow-direct-connections-only="true">
+ <connector-ref>server2-connector</connector-ref>
+ </static-connectors>
+ </cluster-connection>
+ </cluster-connections>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createNonDurableQueue" roles="guest"/>
+ <permission type="deleteNonDurableQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/clustered-static-oneway/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server1/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server1/hornetq-jms.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,31 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="netty-connector"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+
+ <ha>true</ha>
+ <!-- Pause 1 second between connect attempts -->
+ <retry-interval>1000</retry-interval>
+
+ <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+ implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+ pause is the same length -->
+ <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+ <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+ <reconnect-attempts>-1</reconnect-attempts>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server1/hornetq-users.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server1/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server1/hornetq-users.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server1/jndi.properties
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server1/jndi.properties (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server1/jndi.properties 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server2/client-jndi.properties
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server2/client-jndi.properties (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server2/client-jndi.properties 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,16 @@
+#
+# Copyright 2009 Red Hat, Inc.
+# Red Hat licenses this file to you under the Apache License, version
+# 2.0 (the "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:3099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/jms/clustered-static-oneway/server2/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server2/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server2/hornetq-beans.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<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">3099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">3098</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.hornetq.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="HornetQSecurityManager"/>
+ </parameter>
+ </constructor>
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="HornetQServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/jms/clustered-static-oneway/server2/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server2/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server2/hornetq-configuration.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,61 @@
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+ <clustered>true</clustered>
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5447"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ <param key="port" value="5447"/>
+ </acceptor>
+ </acceptors>
+
+ <!-- Clustering configuration -->
+ <cluster-connections>
+ <cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <retry-interval>500</retry-interval>
+ <use-duplicate-detection>true</use-duplicate-detection>
+ <forward-when-no-consumers>true</forward-when-no-consumers>
+ <max-hops>2</max-hops>
+ </cluster-connection>
+ </cluster-connections>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createNonDurableQueue" roles="guest"/>
+ <permission type="deleteNonDurableQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/clustered-static-oneway/server2/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server2/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server2/hornetq-jms.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,45 @@
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="netty-connector"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+
+ <ha>true</ha>
+ <!-- Pause 1 second between connect attempts -->
+ <retry-interval>1000</retry-interval>
+
+ <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+ implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+ pause is the same length -->
+ <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+ <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+ <reconnect-attempts>-1</reconnect-attempts>
+
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server2/hornetq-users.xml
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server2/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server2/hornetq-users.xml 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/server2/jndi.properties
===================================================================
--- trunk/examples/jms/clustered-static-oneway/server2/jndi.properties (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/server2/jndi.properties 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,15 @@
+#
+# Copyright 2009 Red Hat, Inc.
+# Red Hat licenses this file to you under the Apache License, version
+# 2.0 (the "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: trunk/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java
===================================================================
--- trunk/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java (rev 0)
+++ trunk/examples/jms/clustered-static-oneway/src/org/hornetq/jms/example/ClusterStaticOnewayExample.java 2010-12-09 18:29:12 UTC (rev 10028)
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.hornetq.jms.example;
+
+import org.hornetq.common.example.HornetQExample;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+
+/**
+ * A simple example that demonstrates server side load-balancing of messages between the queue instances on different
+ * nodes of the cluster. The cluster is created from a static list of nodes.
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ClusterStaticOnewayExample extends HornetQExample
+{
+ public static void main(final String[] args)
+ {
+ new ClusterStaticOnewayExample().run(args);
+ }
+
+ @Override
+ public boolean runExample() throws Exception
+ {
+ Connection initialConnection = null;
+
+ Connection connection0 = null;
+
+ Connection connection1 = null;
+
+ Connection connection2 = null;
+
+ Connection connection3 = null;
+
+ InitialContext ic0 = null;
+ Thread.sleep(5000);
+ 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");
+
+ //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
+ initialConnection = cf0.createConnection();
+
+ Thread.sleep(2000);
+ // 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 = cf0.createConnection();
+
+ // Step 6. We create a JMS Connection connection0 which is a connection to server 0
+ connection2 = cf0.createConnection();
+
+ // Step 7. We create a JMS Connection connection1 which is a connection to server 1
+ connection3 = cf0.createConnection();
+
+ // Step 8. We create a JMS Session on server 0
+ Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Step 9. We create a JMS Session on server 1
+ Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+
+ // Step 8. We create a JMS Session on server 0
+ Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Step 9. We create a JMS Session on server 1
+ Session session3 = connection3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Step 10. We start the connections to ensure delivery occurs on them
+ connection0.start();
+
+ connection1.start();
+
+ connection2.start();
+
+ connection3.start();
+
+ // Step 11. We create JMS MessageConsumer objects on server 0 and server 1
+ MessageConsumer consumer0 = session0.createConsumer(queue);
+
+ MessageConsumer consumer1 = session1.createConsumer(queue);
+
+ MessageConsumer consumer2 = session2.createConsumer(queue);
+
+ MessageConsumer consumer3 = session3.createConsumer(queue);
+
+ Thread.sleep(2000);
+
+ // Step 12. We create a JMS MessageProducer object on server 3
+ MessageProducer producer = session3.createProducer(queue);
+
+ // Step 13. We send some messages to server 0
+
+ final int numMessages = 20;
+
+ 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());
+ }
+ Thread.sleep(2000);
+ // 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
+ int con0Node = getServer(connection0);
+ int con1Node = getServer(connection1);
+ int con2Node = getServer(connection2);
+ int con3Node = getServer(connection3);
+
+ if(con0Node + con1Node + con2Node + con3Node != 6)
+ {
+ return false;
+ }
+ for (int i = 0; i < numMessages; i += 4)
+ {
+ TextMessage message0 = (TextMessage)consumer0.receive(5000);
+
+ System.out.println("Got message: " + message0.getText() + " from node " + con0Node);
+
+ TextMessage message1 = (TextMessage)consumer1.receive(5000);
+
+ System.out.println("Got message: " + message1.getText() + " from node " + con1Node);
+
+ TextMessage message2 = (TextMessage)consumer2.receive(5000);
+
+ System.out.println("Got message: " + message2.getText() + " from node " + con2Node);
+
+ TextMessage message3 = (TextMessage)consumer3.receive(5000);
+
+ System.out.println("Got message: " + message3.getText() + " from node " + con3Node);
+ }
+
+ return true;
+ }
+ finally
+ {
+ // Step 15. Be sure to close our resources!
+
+ if (initialConnection != null)
+ {
+ initialConnection.close();
+ }
+
+ if (connection0 != null)
+ {
+ connection0.close();
+ }
+
+ if (connection1 != null)
+ {
+ connection1.close();
+ }
+
+ if (connection2 != null)
+ {
+ connection2.close();
+ }
+
+ if (connection3 != null)
+ {
+ connection3.close();
+ }
+
+ if (ic0 != null)
+ {
+ ic0.close();
+ }
+ }
+ }
+
+}
More information about the hornetq-commits
mailing list