[hornetq-commits] JBoss hornetq SVN: r8113 - in trunk: examples/common and 9 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Oct 15 10:32:21 EDT 2009


Author: jmesnil
Date: 2009-10-15 10:32:21 -0400 (Thu, 15 Oct 2009)
New Revision: 8113

Added:
   trunk/examples/jms/jms-bridge/
   trunk/examples/jms/jms-bridge/build.bat
   trunk/examples/jms/jms-bridge/build.sh
   trunk/examples/jms/jms-bridge/build.xml
   trunk/examples/jms/jms-bridge/jms-bridge.png
   trunk/examples/jms/jms-bridge/readme.html
   trunk/examples/jms/jms-bridge/server0/
   trunk/examples/jms/jms-bridge/server0/hornetq-beans.xml
   trunk/examples/jms/jms-bridge/server0/hornetq-configuration.xml
   trunk/examples/jms/jms-bridge/server0/hornetq-jms.xml
   trunk/examples/jms/jms-bridge/server0/hornetq-users.xml
   trunk/examples/jms/jms-bridge/server0/jndi.properties
   trunk/examples/jms/jms-bridge/server1/
   trunk/examples/jms/jms-bridge/server1/hornetq-beans.xml
   trunk/examples/jms/jms-bridge/server1/hornetq-configuration.xml
   trunk/examples/jms/jms-bridge/server1/hornetq-jms.xml
   trunk/examples/jms/jms-bridge/server1/hornetq-users.xml
   trunk/examples/jms/jms-bridge/server1/jndi.properties
   trunk/examples/jms/jms-bridge/src/
   trunk/examples/jms/jms-bridge/src/org/
   trunk/examples/jms/jms-bridge/src/org/hornetq/
   trunk/examples/jms/jms-bridge/src/org/hornetq/jms/
   trunk/examples/jms/jms-bridge/src/org/hornetq/jms/example/
   trunk/examples/jms/jms-bridge/src/org/hornetq/jms/example/JMSBridgeExample.java
Modified:
   trunk/.classpath
   trunk/examples/common/common.css
Log:
https://jira.jboss.org/jira/browse/HORNETQ-177: Create JMS bridge example which demonstrates use of remote machines

* example requires 2 machines each one hosting a HornetQ server.


Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-10-15 13:50:01 UTC (rev 8112)
+++ trunk/.classpath	2009-10-15 14:32:21 UTC (rev 8113)
@@ -40,6 +40,7 @@
 	<classpathentry kind="src" path="examples/jms/instantiate-connection-factory/src"/>
 	<classpathentry kind="src" path="examples/jms/interceptor/src"/>
 	<classpathentry kind="src" path="examples/jms/jaas/src"/>
+	<classpathentry kind="src" path="examples/jms/jms-bridge/src"/>
 	<classpathentry kind="src" path="examples/jms/jmx/src"/>
 	<classpathentry kind="src" path="examples/jms/large-message/src"/>
 	<classpathentry kind="src" path="examples/jms/last-value-queue/src"/>

Modified: trunk/examples/common/common.css
===================================================================
--- trunk/examples/common/common.css	2009-10-15 13:50:01 UTC (rev 8112)
+++ trunk/examples/common/common.css	2009-10-15 14:32:21 UTC (rev 8113)
@@ -19,6 +19,10 @@
   border: dotted grey 1px;
 }
 
+abbr {
+  border-bottom: 1px dotted #333; cursor: help;
+}
+
 .missing-doc {
   background-color: red;
   border: dotted black 1px;

Added: trunk/examples/jms/jms-bridge/build.bat
===================================================================
--- trunk/examples/jms/jms-bridge/build.bat	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/build.bat	2009-10-15 14:32:21 UTC (rev 8113)
@@ -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/jms-bridge/build.sh
===================================================================
--- trunk/examples/jms/jms-bridge/build.sh	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/build.sh	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+export OVERRIDE_ANT_HOME=../../../tools/ant
+
+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/jms-bridge/build.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/jms/jms-bridge/build.xml
===================================================================
--- trunk/examples/jms/jms-bridge/build.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/build.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+<!--
+  ~ 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.
+  -->
+
+<project default="help" name="HornetQ JMS Bridge Example">
+
+   <import file="../../common/build.xml"/>
+
+   <path id="extra.classpath">
+      <dirset dir="build/classes" />
+      <fileset dir="build/lib">
+         <include name="**/*.jar"/>
+   </fileset>
+   </path>
+   <path id="jta.classpath">
+      <fileset dir="build/jta">
+         <include name="**/*.jar"/>
+      </fileset>
+   </path>
+
+   <target name="help">
+      <echo>
+1. make sure to configure source and target servers
+2. on one server, run "./build.sh source-server"
+3. on another server, run "./build.sh target-server"
+4. run the client with "./build.sh client -Dsource=&lt;source server> -Dtarget=&lt;target server>"
+      </echo>
+   </target>
+
+   <target name="init">
+      <mkdir dir="build/classes" />
+      <mkdir dir="build/lib" />
+      <copy todir="build/lib" flatten="true">
+         <fileset dir="${hornetq.jars.dir}">
+            <include name="hornetq-core.jar"/>
+            <include name="hornetq-jms.jar"/>
+            <include name="hornetq-transports.jar"/>
+            <include name="hornetq-bootstrap.jar"/>
+         </fileset>
+         <fileset dir="${jars.dir}">
+            <include name="**/jboss-jms-api.jar" />
+            <include name="**/netty.jar" />
+            <include name="**/jnpserver.jar" />
+            <include name="**/jboss-kernel.jar" />
+            <include name="**/jboss-dependency.jar" />
+            <include name="**/jboss-logging-spi.jar" />
+            <include name="**/jboss-common-core.jar" />
+            <include name="**/jboss-reflect.jar" />
+            <include name="**/jboss-mdr.jar" />
+            <include name="**/jbossxb.jar" />
+            <include name="**/jboss-mc.jar" />
+         </fileset>
+      </copy>
+      <mkdir dir="build/jta" />
+      <!-- Transaction libraries are required by the JMS bridge -->
+      <get usetimestamp="true" src="http://repository.jboss.com/jboss/jbossts/4.6.0.CR1/lib/jbossjta.jar" dest="build/jta/jbossjta.jar"/>
+      <get usetimestamp="true" src="http://repository.jboss.com/jboss/jbossts/4.6.0.CR1/lib/jbossts-common.jar" dest="build/jta/jbossts-common.jar"/>
+      <get usetimestamp="true" src="http://repository.jboss.com/jboss/jboss-javaee/5.0.1.GA/lib/jboss-javaee.jar" dest="build/jta/jboss-javaee.jar"/>
+      <get usetimestamp="true" src="http://repository.jboss.com/apache-log4j/1.2.14/lib/log4j.jar" dest="build/jta/log4j.jar"/>
+      <get usetimestamp="true" src="http://repository.jboss.com/apache-logging/1.1/lib/commons-logging.jar" dest="build/jta/commons-logging.jar"/>
+   </target>
+
+   <target name="source-server" depends="compile">
+      <echo message="Start *SOURCE* server" />
+
+      <java classname="org.hornetq.integration.bootstrap.HornetQBootstrapServer"  fork="true">
+         <sysproperty key="java.library.path" value="${java.library.path}${path.separator}${aio.library.path}"/>
+         <sysproperty key="com.sun.management.jmxremote" value="" />
+         <classpath refid="extra.classpath"/>
+         <classpath path="server0/" />
+         <arg line="server0/hornetq-beans.xml"/>
+      </java>
+   </target>
+
+   <target name="target-server" depends="compile">
+      <echo message="Start *TARGET* server" />
+
+      <java classname="org.hornetq.integration.bootstrap.HornetQBootstrapServer"  fork="true">
+         <sysproperty key="java.library.path" value="${java.library.path}${path.separator}${aio.library.path}"/>
+         <sysproperty key="com.sun.management.jmxremote" value="" />
+         <classpath refid="extra.classpath"/>
+         <classpath refid="jta.classpath"/>
+         <classpath path="server1/" />
+         <arg line="server1/hornetq-beans.xml"/>
+      </java>
+   </target>
+
+   <target name="client" depends="compile">
+      <echo message="Start client" />
+      <java classname="org.hornetq.jms.example.JMSBridgeExample"  fork="true">
+         <classpath refid="extra.classpath"/>
+         <arg line="${source} ${target}"/>
+      </java>
+   </target>
+</project>

Added: trunk/examples/jms/jms-bridge/jms-bridge.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/jms/jms-bridge/jms-bridge.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/jms/jms-bridge/readme.html
===================================================================
--- trunk/examples/jms/jms-bridge/readme.html	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/readme.html	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,290 @@
+<html>
+  <head>
+    <title>HornetQ JMS Bridge 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 Bridge Example</h1>
+     <p>This example shows you how to setup a JMS Bridge between two HornetQ servers.</p>
+     <img src="jms-bridge.png"  />
+     <p>The example will use two HornetQ servers:</p>
+     <ul>
+        <li>Server #0 &ndash; the <em>Source</em> server. It will be configured with a JMS Topic bound to JNDI under <code>/source/topic</code>
+        <li>Server #1 &ndash; the <em>Target</em> server. It will be configured with a JMS Queue bound to JNDI under <code>/target/queue</code><br />
+     </ul>
+     <p>Both HornetQ server will run their own JNDI server used by the JMS Bridge and the JMS Client to lookup JMS
+        resources (ConnectionFactory and Destination).</p>
+     <p>The JMS Bridge will run inside the target server and is configured to bridge messages from the <em>source</em> destination     
+     (the topic hosted on server #0) and the <em>target</em> destination (the queue hosted on server #1)</p>
+     <p>The client will check the bridge works by:</p>
+     <ol>
+        <li>sending a message to the <em>source</em> topic</li>
+        <li>receive a message from the <em>target</em> queue</li>
+        <li>check that both messages correspond to the same content.</li>
+     </ol>
+     <p>Please note that this example is meant to run on 2 different machines. If you want to run it on a single machine,
+        you will have also to make sure that the HornetQ servers do not share any ports.</p>
+     <h2>Example Configuration</h2>
+     <p>To run this example on 2 machines, you will need to adapt the configuration to your machines:</p>
+     <ol>
+        <li>Setup the source server address so that both the JMS bridge and the JMS
+           client can connect to its JNDI server and send/receive message from it</li>
+        <li>Setup the target server so that both the JMS bridge and the JMS
+           client can connect to its JNDI server and send/receive message from it</li>
+        <li>Setup the JMS Bridge configuration so that it can receive message from the source
+           topic and send them to the target queue</li>
+     </ol>
+     <p>As an example, I will use the following network addresses to show how to configure the example:</p>
+     <ul>
+        <li>Server #0 &ndash; <code>192.168.0.<strong>10</strong></code></li>
+        <li>Server #1 &ndash; <code>192.168.0.<strong>11</strong></code></li>
+     </ul>
+     <p>First, make sure that HornetQ <em>is setup and installed on both servers</em></p>
+     <p>Then, you will have to adapt each server configuration on their respective servers:
+     <ul>
+        <li>Server #0 configuration (located in <code>server0/</code>) must be changed on Server #0</li>
+        <li>Server #1 configuration (located in <code>server1/</code>) must be changed on Server #1</li>
+     </ul>
+     <h3>Source Server Configuration</h3>
+     <p>On server #0, in <code>server0/hornetq-beans.xml</code>, setup the JNDI server network address by replacing
+        <code>@SOURCE_SERVER</code> by the source server address (e.g. <code>192.168.0.10</code>):</p>
+     <pre class="prettyprint">
+        &lt;bean name="JNDIServer" class="org.jnp.server.Main">
+           ...
+           &lt;!-- **************************************** -->
+           &lt;!-- Replace with the *source* server address -->
+           &lt;!-- **************************************** -->
+           &lt;property name="bindAddress">192.168.0.10&lt;/property>
+           &lt;!-- **************************************** -->
+           &lt;!-- Replace with the *source* server address -->
+           &lt;!-- **************************************** -->
+           &lt;property name="rmiBindAddress">192.168.0.10&lt;/property>
+           ...
+        &lt;/bean>
+     </pre>
+     <p>In <code>server0/hornetq-configuration.xml</code>, configure a Netty connector with the source
+        server address:</p>
+     <pre class="prettyprint">
+        &lt;connectors>
+           &lt;connector name="netty">
+              &lt;factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory&lt;/factory-class>
+              &lt;!-- **************************************** -->
+              &lt;!-- Replace with the *source* server address -->
+              &lt;!-- **************************************** -->
+              &lt;param key="hornetq.remoting.netty.host" value="192.168.0.10" type="String"/>
+           &lt;/connector>
+        &lt;/connectors>
+     </pre>
+     <p>Note that in <code>server0/hornetq-configuration.xml</code>, we also setup the Netty <em>acceptor</em> to accept connections from any of the source server addresses
+        (by specifying <code>0.0.0.0</code>)</p>
+     <p>The source server defines two JMS resources in <code>server0/hornetq-jms.xml</code>:</p>
+     <ul>
+        <li>A JMS ConnectionFactory bound to <code>/source/ConnectionFactory</code></li>
+        <li>A JMS Topic bound to <code>/source/topic</code></li>
+     </ul>
+     <h3>Target Server Configuration</h3>
+     <p>On server #1, in <code>server1/hornetq-beans.xml</code>, setup the JNDI server network address by replacing
+        <code>@TARGET_SERVER</code> by the target server address (e.g. <code>192.168.0.11</code>):</p>
+     <pre class="prettyprint">
+        &lt;bean name="JNDIServer" class="org.jnp.server.Main">
+           ...
+           &lt;!-- **************************************** -->
+           &lt;!-- Replace with the *target* server address -->
+           &lt;!-- **************************************** -->
+           &lt;property name="bindAddress">192.168.0.11&lt;/property>
+           &lt;!-- **************************************** -->
+           &lt;!-- Replace with the *target* server address -->
+           &lt;!-- **************************************** -->
+           &lt;property name="rmiBindAddress">192.168.0.11&lt;/property>
+           ...
+        &lt;/bean>
+     </pre>
+     <p>In <code>server1/hornetq-configuration.xml</code>, configure a Netty connector with the target
+        server address:</p>
+     <pre class="prettyprint">
+        &lt;connectors>
+           &lt;connector name="netty">
+              &lt;factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory&lt;/factory-class>
+              &lt;!-- **************************************** -->
+              &lt;!-- Replace with the *target* server address -->
+              &lt;!-- **************************************** -->
+              &lt;param key="hornetq.remoting.netty.host" value="192.168.0.11" type="String"/>
+           &lt;/connector>
+        &lt;/connectors>
+     </pre>
+     <p>Note that in <code>server1/hornetq-configuration.xml</code>, we also setup the Netty <em>acceptor</em> to accept connections from any of the target server addresses
+        (by specifying <code>0.0.0.0</code>)</p>
+     <p>The target server defines two JMS resources in <code>server1/hornetq-jms.xml</code>:</p>
+     <ul>
+        <li>A JMS ConnectionFactory bound to <code>/target/ConnectionFactory</code></li>
+        <li>A JMS Queue bound to <code>/target/queue</code></li>
+     </ul>
+
+     <h3>JMS Bridge Configuration</h3>
+     <p>The JMS Bridge is a <abbr title="Plain Old Java Object">POJO</abbr> in which we inject JNDI configurations
+        so that it looks up its source and target JMS resources.
+        The JMS Bridge is defined a bean and setup by JBoss Microntainer in the same VM than Server #1, the target server.</p>
+
+      </p>The JMS Bridge is defined by the <code>JMSBridge</code> bean in <code>server1/hornetq-beans.xml</code>:</p>
+      <pre class="prettyprint">
+         &lt;!-- The JMS Bridge -->
+         &lt;bean name="JMSBridge" class="org.hornetq.jms.bridge.impl.JMSBridgeImpl">
+         ...
+         &lt;/bean>
+      </pre>
+      <p>the <code>JMSBridgeImpl</code> constructor is used to inject all the properties required to run the JMS Bridge.</p>
+      <p>Its first four arguments defines how the bridge will lookup:</p>
+      <ol>
+         <li>its <em>source</em> JMS ConnectionFactory</li>
+         <li>its <em>source</em> JMS Destination</li>
+         <li>its <em>target</em> JMS ConnectionFactory</li>
+         <li>its <em>target</em> JMS Destination</li>
+     </ol>
+     <p>Using other POJOs, the JMS Bridge is configured to retrieve:</p>
+     <ul>
+        <li>its <em>source</em> JMS ConnectionFactory by looking up <code>/source/ConnectionFactory</code> using
+           the <code>SourceJNDI</code> configuration</li>
+        <li>its <em>source</em> JMS Destination by looking up <code>/source/topic</code> using
+           the <code>SourceJNDI</code> configuration</li>
+        <li>its <em>target</em> JMS ConnectionFactory by looking up <code>/target/ConnectionFactory</code> using
+           the <code>TargetJNDI</code> configuration</li>
+           <li>its <em>target</em> JMS ConnectionFactory by looking up <code>/target/queue</code> using
+        the <code>TargetJNDI</code> configuration</li>
+     </ul>
+     <p>In turn, <code>SourceJNDI</code> and <code>TargetJNDI</code> are POJOs defining how to connect to JNDI server.
+        SourceJNDI URL must point to your source server, while LocalJNDI must point to your target server:</p>
+   <pre class="prettyprint">
+      &lt;bean name="SourceJNDI" class="java.util.Hashtable">
+         ...
+                &lt;entry>
+                   &lt;key>java.naming.provider.url&lt;/key>
+                   &lt;!-- **************************************** -->
+                   &lt;!-- Replace with the *source* server address -->
+                   &lt;!-- **************************************** -->
+                   &lt;value>jnp://192.168.0.10:1099&lt;/value>
+         ...
+       &lt;/bean>
+       &lt;bean name="TargetJNDI" class="java.util.Hashtable">
+         ...
+                &lt;ntry>
+                   &lt;key>java.naming.provider.url&lt;/key>
+                   &lt;!-- **************************************** -->
+                   &lt;!-- Replace with the *target* server address -->
+                   &lt;!-- **************************************** -->
+                   &lt;value>jnp://1192.168.0.11:1099&lt;/value>
+                &lt;/entry>
+         ...
+       &lt;/bean>
+      </pre>
+     <h2>Example step-by-step</h2>
+     <p>To run the example after having setup both HornetQ servers and the JMS bridge:</p>
+     <ol>
+        <li>on Server #0, run <code>./build.sh source-server</code></li>
+        <li>on Server #1, run <code>./build.sh target-server</code> (this will start the JMS Bridge too)</li>
+        <li>on either server, run the client: 
+           <code>./build.sh client -Dsource=&lt;source server address> -Dtarget=&lt;target server address></code>
+           (for example: 
+           <code>./build.sh client -Dsource=192.168.0.11 -Dtarget=192.168.0.11</code>)</li>
+      </ol>
+      <p>Let's look at the Client code (in <code>JMSBridgeExample</code> class):</p>
+     <ol>
+        <li>First we need to get an initial context so we can look-up the JMS resources (using the source and target server
+           addresses passed as arguments to <code>./build.sh client</code>)</li>
+        <pre class="prettyprint">
+           InitialContext sourceContext = createContext(sourceServer);
+           InitialContext targetContext = createContext(targetServer);
+        </pre>
+
+        <li>We look up the JMS resources from the Source server</li>
+        <pre class="prettyprint">
+           ConnectionFactory sourceConnectionFactory = (ConnectionFactory)sourceContext.lookup("/source/ConnectionFactory");
+           Topic sourceTopic = (Topic)sourceContext.lookup("/source/topic");
+        </pre>
+
+        <li>We create JMS objects to send a message to the source destination</li>
+        <pre class="prettyprint">
+           sourceConnection = sourceConnectionFactory.createConnection();
+           Session sourceSession = sourceConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+           MessageProducer sourceProducer = sourceSession.createProducer(sourceTopic);
+        </pre>
+
+        <li>We send a message to the source destination</li>
+        <pre class="prettyprint">
+           TextMessage message = sourceSession.createTextMessage("this is a text message sent at " + System.currentTimeMillis());
+           sourceProducer.send(message);
+        </pre>
+        
+        <li>We close the connection to the source server</li>
+        <pre class="prettyprint">
+           sourceConnection.close();
+        </pre>
+
+        <p>At this point, the JMS Bridge will consume the message from the source topic and
+           sends it to the target queue. 
+           The client will check the bridge works by consuming a message from the target queue.</p>
+
+        <li>We look up the JMS resources from the target server</li>
+        <pre class="prettyprint">
+           ConnectionFactory targetConnectionFactory = (ConnectionFactory)targetContext.lookup("/target/ConnectionFactory");
+           Queue targetQueue = (Queue)targetContext.lookup("/target/queue");
+        </pre>
+
+        <li>We create JMS objects to receive a message from the target destination</li>
+        <pre class="prettyprint">
+           targetConnection = targetConnectionFactory.createConnection();
+           Session targetSession = targetConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+           MessageConsumer targetConsumer = targetSession.createConsumer(targetQueue);
+       </pre>
+
+        <li>We start the target connection to start receiving messages
+        <pre class="prettyprint">
+           targetConnection.start();
+        </pre>
+
+        <li>We receive the message and print it. Its content is the same than the message
+           the client sent to the source topic</li>
+        <pre class="prettyprint">
+           TextMessage messageReceived = (TextMessage)targetConsumer.receive(5000);
+        </pre>
+
+        <li>We display the message ID and its "bridged" message ID</li>
+        <pre class="prettyprint">
+           System.out.format("Message ID         : %s\n", messageReceived.getJMSMessageID());
+           System.out.format("Bridged Message ID : %s\n", messageReceived.getStringProperty("HQ_BRIDGE_MSG_ID_LIST"));
+        </pre>
+        
+        <p>Note that the message received from the target queue is <em>not the same message</em> sent to the source topic
+           (their message IDs are different) but they have the <em>same content</em>.
+
+        <li>And finally, <b>always</b> remember to close your JMS connections and 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 (initialContext != null)
+              {
+                initialContext.close();
+              }
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+
+
+
+     </ol>
+     
+     <h2>More information</h2>
+
+     <ul>
+        <li>User Manual's <a href="../../../docs/user-manual/en/html_single/appserver-integration.html#jms-bridge">JMS Bridge chapter</a></li>
+        <li>The <a href="../../javaee/jms-bridge/readme.html">Java EE JMS Bridge example</a> shows how to configure a JMS Bridge
+           inside JBoss Application Server to bridge destinations from the same server.</a>
+     </p>
+
+  </body>
+</html>
\ No newline at end of file

Added: trunk/examples/jms/jms-bridge/server0/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server0/hornetq-beans.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server0/hornetq-beans.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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>
+      <!-- **************************************** -->
+      <!-- Replace with the *source* server address -->
+      <!-- **************************************** -->
+      <property name="bindAddress">@SOURCE_SERVER@</property>
+      <!-- **************************************** -->
+      <!-- Replace with the *source* server address -->
+      <!-- **************************************** -->
+      <property name="rmiBindAddress">@SOURCE_SERVER@</property>
+      <property name="port">1099</property>
+      <property name="rmiPort">1098</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.core.security.impl.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/jms-bridge/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server0/hornetq-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server0/hornetq-configuration.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,32 @@
+ <configuration xmlns="urn:hornetq"
+               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+               xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+   <connectors>
+      <connector name="netty">
+         <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
+         <!-- **************************************** -->
+         <!-- Replace with the *source* server address -->
+         <!-- **************************************** -->
+         <param key="hornetq.remoting.netty.host" value="@SOURCE_SERVER@" type="String"/>
+      </connector>
+   </connectors>
+
+   <acceptors>
+      <acceptor name="netty">
+         <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
+         <!-- the server accepts connections on all the server addresses -->
+         <param key="hornetq.remoting.netty.host" value="0.0.0.0" type="String"/>
+      </acceptor>
+   </acceptors>
+
+   <security-settings>
+         <security-setting match="jms.#">
+            <permission type="consume" roles="guest"/>
+            <permission type="send" roles="guest"/>
+            <permission type="createTempQueue" roles="guest"/>
+            <permission type="deleteTempQueue" roles="guest"/>
+         </security-setting>
+    </security-settings>
+</configuration>
+ 
\ No newline at end of file

Added: trunk/examples/jms/jms-bridge/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server0/hornetq-jms.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server0/hornetq-jms.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,15 @@
+<configuration xmlns="urn:hornetq"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty"/>
+      <entries>
+         <entry name="/source/ConnectionFactory"/>
+      </entries>
+   </connection-factory>
+
+   <topic name="topic">
+      <entry name="/source/topic"/>
+   </topic>
+</configuration>
\ No newline at end of file

Added: trunk/examples/jms/jms-bridge/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server0/hornetq-users.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server0/hornetq-users.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -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/jms-bridge/server0/jndi.properties
===================================================================
--- trunk/examples/jms/jms-bridge/server0/jndi.properties	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server0/jndi.properties	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/jms-bridge/server1/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server1/hornetq-beans.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server1/hornetq-beans.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,213 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<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>
+      <!-- **************************************** -->
+      <!-- Replace with the *target* server address -->
+      <!-- **************************************** -->
+      <property name="bindAddress">@TARGET_SERVER@</property>
+      <!-- **************************************** -->
+      <!-- Replace with the *target* server address -->
+      <!-- **************************************** -->
+      <property name="rmiBindAddress">@TARGET_SERVER@</property>
+      <property name="port">1099</property>
+      <property name="rmiPort">1098</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.core.security.impl.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>
+   
+   <!-- The JMS Bridge -->
+   <bean name="JMSBridge" class="org.hornetq.jms.bridge.impl.JMSBridgeImpl">
+           <constructor>
+               <!-- Source ConnectionFactory Factory -->
+               <parameter>
+                   <inject bean="SourceCFF"/>
+               </parameter>
+               <!-- Target ConnectionFactory Factory -->
+               <parameter>
+                   <inject bean="TargetCFF"/>
+               </parameter>
+               <!-- Source DestinationFactory -->
+               <parameter>
+                   <inject bean="SourceDestinationFactory"/>
+               </parameter>
+               <!-- Target DestinationFactory -->
+               <parameter>
+                   <inject bean="TargetDestinationFactory"/>
+               </parameter>
+               <!-- Source username (no username here) -->
+               <parameter><null /></parameter>
+               <!-- Source password (no password here)-->
+               <parameter><null /></parameter>
+               <!-- Target username (no username here)-->
+               <parameter><null /></parameter>
+               <!-- Target password (no password here)-->
+               <parameter><null /></parameter>
+               <!-- Selector -->
+               <parameter><null /></parameter>
+               <!-- Interval to retry in case of failure (in ms) -->
+               <parameter>5000</parameter>
+               <!-- Maximum number of retries to connect to the source and target -->
+               <parameter>10</parameter>
+               <!-- Quality of service -->
+               <parameter>ONCE_AND_ONLY_ONCE</parameter>
+               <!-- Maximum batch size -->
+               <parameter>1</parameter>
+               <!-- Maximum batch time (-1 means infinite) -->
+               <parameter>-1</parameter>
+               <!-- Subscription name (no subscription name here)-->
+               <parameter><null /></parameter>
+               <!-- client ID  (no client ID here)-->
+               <parameter><null /></parameter>
+               <!-- concatenate JMS messageID to the target's message header -->
+               <parameter>true</parameter>
+           </constructor>
+           <property name="transactionManager">
+               <inject bean="TransactionManager"/>
+           </property>
+           
+           <!-- HornetQ JMS Server must be started before the bridge -->
+           <depends>JMSServerManager</depends>
+           
+       </bean>
+
+       <bean name="TransactionManager" class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple">
+       </bean>
+
+       <!-- SourceCFF describes the ConnectionFactory used to connect to the source destination -->
+       <bean name="SourceCFF" class="org.hornetq.jms.bridge.impl.JNDIConnectionFactoryFactory">
+           <constructor>
+               <parameter>
+                   <inject bean="SourceJNDI" />
+               </parameter>
+               <parameter>/source/ConnectionFactory</parameter>
+           </constructor>  
+       </bean>
+
+       <!-- TargetCFF describes the ConnectionFactory used to connect to the target destination -->
+       <bean name="TargetCFF" class="org.hornetq.jms.bridge.impl.JNDIConnectionFactoryFactory">
+           <constructor>
+               <parameter>
+                   <inject bean="TargetJNDI" />
+               </parameter>
+               <parameter>/target/ConnectionFactory</parameter>
+           </constructor>  
+       </bean>
+
+       <!-- SourceDestinationFactory describes the Destination used as the source -->
+       <bean name="SourceDestinationFactory" class="org.hornetq.jms.bridge.impl.JNDIDestinationFactory">
+           <constructor>
+               <parameter>
+                   <inject bean="SourceJNDI" />
+               </parameter>
+               <parameter>/source/topic</parameter>
+           </constructor>  
+       </bean>
+
+       <!-- TargetDestinationFactory describes the Destination used as the target -->
+       <bean name="TargetDestinationFactory" class="org.hornetq.jms.bridge.impl.JNDIDestinationFactory">
+           <constructor>
+               <parameter>
+                   <inject bean="TargetJNDI" />
+               </parameter>
+               <parameter>/target/queue</parameter>
+           </constructor>  
+       </bean>
+       
+       <!-- JNDI is a Hashtable containing the JNDI properties required -->
+       <!-- to connect to the *source* JMS resources                    -->       
+      <bean name="SourceJNDI" class="java.util.Hashtable">
+         <constructor class="java.util.Map">
+            <map class="java.util.Hashtable" keyClass="java.lang.String"
+                                             valueClass="java.lang.String">
+               <entry>
+                  <key>java.naming.factory.initial</key>
+                  <value>org.jnp.interfaces.NamingContextFactory</value>
+               </entry>
+               <entry>
+                  <key>java.naming.provider.url</key>
+                  <!-- **************************************** -->
+                  <!-- Replace with the *source* server address -->
+                  <!-- **************************************** -->
+                  <value>jnp://@SOURCE_SERVER@:1099</value>
+               </entry>
+               <entry>
+                  <key>java.naming.factory.url.pkgs</key>
+                  <value>org.jboss.naming:org.jnp.interfaces"</value>
+               </entry>
+            </map>
+         </constructor>
+      </bean>
+      
+      <!-- JNDI is a Hashtable containing the JNDI properties required -->
+      <!-- to connect to the *target* JMS resources                    -->       
+      <bean name="TargetJNDI" class="java.util.Hashtable">
+         <constructor class="java.util.Map">
+            <map class="java.util.Hashtable" keyClass="java.lang.String"
+                                             valueClass="java.lang.String">
+               <entry>
+                  <key>java.naming.factory.initial</key>
+                  <value>org.jnp.interfaces.NamingContextFactory</value>
+               </entry>
+               <entry>
+                  <key>java.naming.provider.url</key>
+                  <!-- **************************************** -->
+                  <!-- Replace with the *target* server address -->
+                  <!-- **************************************** -->
+                  <value>jnp://@TARGET_SERVER@:1099</value>
+               </entry>
+               <entry>
+                  <key>java.naming.factory.url.pkgs</key>
+                  <value>org.jboss.naming:org.jnp.interfaces"</value>
+               </entry>
+            </map>
+         </constructor>
+      </bean>
+
+</deployment>

Added: trunk/examples/jms/jms-bridge/server1/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server1/hornetq-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server1/hornetq-configuration.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,32 @@
+ <configuration xmlns="urn:hornetq"
+               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+               xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+   <connectors>
+      <connector name="netty">
+         <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
+         <!-- **************************************** -->
+         <!-- Replace with the *target* server address -->
+         <!-- **************************************** -->
+         <param key="hornetq.remoting.netty.host" value="@TARGET_SERVER@" type="String"/>
+      </connector>
+   </connectors>
+
+   <acceptors>
+      <acceptor name="netty">
+         <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
+         <!-- the server accepts connections on all the server addresses -->
+         <param key="hornetq.remoting.netty.host" value="0.0.0.0" type="String"/>
+      </acceptor>
+   </acceptors>
+
+   <security-settings>
+         <security-setting match="jms.#">
+            <permission type="consume" roles="guest"/>
+            <permission type="send" roles="guest"/>
+            <permission type="createTempQueue" roles="guest"/>
+            <permission type="deleteTempQueue" roles="guest"/>
+         </security-setting>
+    </security-settings>
+</configuration>
+ 
\ No newline at end of file

Added: trunk/examples/jms/jms-bridge/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server1/hornetq-jms.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server1/hornetq-jms.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,15 @@
+<configuration xmlns="urn:hornetq"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty"/>
+      <entries>
+         <entry name="/target/ConnectionFactory"/>
+      </entries>
+   </connection-factory>
+
+   <queue name="target">
+      <entry name="/target/queue"/>
+   </queue>
+</configuration>
\ No newline at end of file

Added: trunk/examples/jms/jms-bridge/server1/hornetq-users.xml
===================================================================
--- trunk/examples/jms/jms-bridge/server1/hornetq-users.xml	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server1/hornetq-users.xml	2009-10-15 14:32:21 UTC (rev 8113)
@@ -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/jms-bridge/server1/jndi.properties
===================================================================
--- trunk/examples/jms/jms-bridge/server1/jndi.properties	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/server1/jndi.properties	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/jms-bridge/src/org/hornetq/jms/example/JMSBridgeExample.java
===================================================================
--- trunk/examples/jms/jms-bridge/src/org/hornetq/jms/example/JMSBridgeExample.java	                        (rev 0)
+++ trunk/examples/jms/jms-bridge/src/org/hornetq/jms/example/JMSBridgeExample.java	2009-10-15 14:32:21 UTC (rev 8113)
@@ -0,0 +1,130 @@
+/*
+ * 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 java.util.Hashtable;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+/**
+ * An example which sends a message to a source topic and consume from a target queue.
+ * The source and target destinations are located on 2 different HornetQ server.
+ * The source and target queues are bridged by a JMS Bridge configured and running on the "target" server.
+ * 
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class JMSBridgeExample
+{
+   public static void main(String[] args) throws Exception
+   {
+      if (args.length != 2)
+      {
+         throw new IllegalArgumentException("JMSBridgeExample needs 2 arguments: <source server> <target server>");
+      }
+      String sourceServer = args[0];
+      String targetServer = args[1];
+
+      System.out.println("client will publish messages to " + sourceServer +
+                         " and receives message from " +
+                         targetServer);
+
+      // Step 1. Create JNDI contexts for source and target servers
+      InitialContext sourceContext = createContext(sourceServer);
+      InitialContext targetContext = createContext(targetServer);
+
+      Connection sourceConnection = null;
+      Connection targetConnection = null;
+      try
+      {
+         // Step 2. Lookup the *source* JMS resources
+         ConnectionFactory sourceConnectionFactory = (ConnectionFactory)sourceContext.lookup("/source/ConnectionFactory");
+         Topic sourceTopic = (Topic)sourceContext.lookup("/source/topic");
+
+         // Step 3. Create a connection, a session and a message producer for the *source* topic
+         sourceConnection = sourceConnectionFactory.createConnection();
+         Session sourceSession = sourceConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer sourceProducer = sourceSession.createProducer(sourceTopic);
+
+         // Step 4. Create and send a text message to the *source* queue
+         TextMessage message = sourceSession.createTextMessage("this is a text message sent at " + System.currentTimeMillis());
+         sourceProducer.send(message);
+         System.out.format("Sent message to %s: %s\n",
+                           ((Topic)message.getJMSDestination()).getTopicName(),
+                           message.getText());
+         System.out.format("Message ID : %s\n", message.getJMSMessageID());
+
+         // Step 5. Close the *source* connection
+         sourceConnection.close();
+
+         // Step 6. Lookup the *target* JMS resources
+         ConnectionFactory targetConnectionFactory = (ConnectionFactory)targetContext.lookup("/target/ConnectionFactory");
+         Queue targetQueue = (Queue)targetContext.lookup("/target/queue");
+
+         // Step 7. Create a connection, a session and a message consumer for the *target* queue
+         targetConnection = targetConnectionFactory.createConnection();
+         Session targetSession = targetConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer targetConsumer = targetSession.createConsumer(targetQueue);
+
+         // Step 8. Start the connection to receive messages from the *target* queue
+         targetConnection.start();
+
+         // Step 9. Receive a message from the *target* queue
+         TextMessage messageReceived = (TextMessage)targetConsumer.receive(5000);
+         System.out.format("\nReceived from %s: %s\n",
+                           ((Queue)messageReceived.getJMSDestination()).getQueueName(),
+                           messageReceived.getText());
+
+         // Step 10. Display the received message's ID and this "bridged" message ID
+         System.out.format("Message ID         : %s\n", messageReceived.getJMSMessageID());
+         System.out.format("Bridged Message ID : %s\n", messageReceived.getStringProperty("HQ_BRIDGE_MSG_ID_LIST"));
+      }
+      finally
+      {
+         // Step 11. Be sure to close the resources!
+         if (sourceContext != null)
+         {
+            sourceContext.close();
+         }
+         if (targetContext != null)
+         {
+            targetContext.close();
+         }
+         if (sourceConnection != null)
+         {
+            sourceConnection.close();
+         }
+         if (targetConnection != null)
+         {
+            targetConnection.close();
+         }
+      }
+   }
+
+   private static InitialContext createContext(String server) throws Exception
+   {
+      String jndiURL = "jnp://" + server + ":1099";
+      Hashtable<String, String> jndiProps = new Hashtable<String, String>();
+      jndiProps.put("java.naming.provider.url", jndiURL);
+      jndiProps.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+      jndiProps.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+      return new InitialContext(jndiProps);
+   }
+}



More information about the hornetq-commits mailing list