title: HornetQ JMS Bridge between two HornetQ servers fails to deliver
body: <p>(Edited on 11.11.11, edits at bottom)</p>
  
  <p>I have two JBoss AS 6.1 servers running HornetQ (version 2.2.5 AS7) servers.
  Lets call the other one CLIENT and other one MASTER.</p>
  
  <p>CLIENT has a Queue ("sourceQueue"), which is written to by our web application.</p>
  
  <p>There is a JMS bridge set up between CLIENT and MASTER servers,
  which consumes messages from sourceQueue on CLIENT and should produce them on
  the targetQueue on MASTER. The bridge is running on the CLIENT JBoss.</p>
  
  <p>PROBLEM: Instead of consuming from source and producing messages on target, superficially nothing seems to happen: the source has 1 message, target has none. It is also possible that the source is being fed that message over and over.</p>
  
  <p>Network connection using netty connectors is working, this has been tested restarting the bridge and observing the netstat -n -c output.</p>
  
  <p>What kind of issues could cause this kind of problems?</p>
  
  <ul>
  <li>Network issues?</li>
  <li>Transaction manager?</li>
  <li>Connector errors?</li>
  </ul>
  
  <p>How would you go about diagnosing problems with HornetQ bridge?</p>
  
  <p>Below is the bridge definition on hornetq-jboss-beans.xml (on CLIENT /jboss/server/default/deploy/hornetq ). Definition is close variation of the JMS bridge example on <a href="http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/jms-bridge.html" rel="nofollow" title="HornetQ Manual">HornetQ manual</a>:</p>
  
  <pre><code>   &lt;bean name="JMSBridge" class="org.hornetq.jms.bridge.impl.JMSBridgeImpl"&gt;
             &lt;!-- HornetQ must be started before the bridge --&gt;
             &lt;depends&gt;HornetQServer&lt;/depends&gt;
             &lt;constructor&gt;
                 &lt;!-- Source ConnectionFactory Factory --&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="SourceCFF"/&gt;
                 &lt;/parameter&gt;
                 &lt;!-- Target ConnectionFactory Factory --&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="TargetCFF"/&gt;
                 &lt;/parameter&gt;
                 &lt;!-- Source DestinationFactory --&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="SourceDestinationFactory"/&gt;
                 &lt;/parameter&gt;
                 &lt;!-- Target DestinationFactory --&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="TargetDestinationFactory"/&gt;
                 &lt;/parameter&gt;
                 &lt;!-- Source User Name (no username here) --&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Source Password (no password here)--&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Target User Name (no username here)--&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Target Password (no password here)--&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Selector --&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Failure Retry Interval (in ms) --&gt;
                 &lt;parameter&gt;5000&lt;/parameter&gt;
                 &lt;!-- Max Retries --&gt;
                 &lt;parameter&gt;10&lt;/parameter&gt;
                 &lt;!-- Quality Of Service --&gt;
                 &lt;parameter&gt;ONCE_AND_ONLY_ONCE&lt;/parameter&gt;
                 &lt;!-- Max Batch Size --&gt;
                 &lt;parameter&gt;1&lt;/parameter&gt;
                 &lt;!-- Max Batch Time (-1 means infinite) --&gt;
                 &lt;parameter&gt;-1&lt;/parameter&gt;
                 &lt;!-- Subscription name (no subscription name here)--&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Client ID  (no client ID here)--&gt;
                 &lt;parameter&gt;&lt;null /&gt;&lt;/parameter&gt;
                 &lt;!-- Add MessageID In Header --&gt;
                 &lt;parameter&gt;true&lt;/parameter&gt;
                 &lt;!-- register the JMS Bridge in the AS MBeanServer --&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="MBeanServer"/&gt;
                 &lt;/parameter&gt;
                 &lt;parameter&gt;org.hornetq:service=MyJMSBridge&lt;/parameter&gt;
               &lt;/constructor&gt;
             &lt;property name="transactionManager"&gt;
                 &lt;inject bean="RealTransactionManager"/&gt;
             &lt;/property&gt;
         &lt;/bean&gt;
  
         &lt;!-- SourceCFF describes the ConnectionFactory used to connect to the
              source destination --&gt;
         &lt;bean name="SourceCFF"
              class="org.hornetq.jms.bridge.impl.JNDIConnectionFactoryFactory"&gt;
             &lt;constructor&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="sourceJNDI" /&gt;
                 &lt;/parameter&gt;
                 &lt;parameter&gt;/XAConnectionFactory&lt;/parameter&gt;
             &lt;/constructor&gt;
         &lt;/bean&gt;
  
         &lt;!-- TargetCFF describes the ConnectionFactory used to connect to the
          target destination --&gt;
         &lt;bean name="TargetCFF"
              class="org.hornetq.jms.bridge.impl.JNDIConnectionFactoryFactory"&gt;
             &lt;constructor&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="targetJNDI" /&gt;
                 &lt;/parameter&gt;
                 &lt;parameter&gt;/integration/XAConnectionFactory&lt;/parameter&gt;
             &lt;/constructor&gt;
         &lt;/bean&gt;
  
         &lt;!-- SourceDestinationFactory describes the Destination used as the source --&gt;
         &lt;bean name="SourceDestinationFactory"
              class="org.hornetq.jms.bridge.impl.JNDIDestinationFactory"&gt;
             &lt;constructor&gt;
                 &lt;parameter&gt;
                    &lt;inject bean="sourceJNDI"/&gt;
                 &lt;/parameter&gt;
                 &lt;parameter&gt;/jms/notificationRequestQueue&lt;/parameter&gt;
             &lt;/constructor&gt;
         &lt;/bean&gt;
  
         &lt;!-- TargetDestinationFactory describes the Destination used as the target --&gt;
         &lt;bean name="TargetDestinationFactory"
              class="org.hornetq.jms.bridge.impl.JNDIDestinationFactory"&gt;
             &lt;constructor&gt;
                 &lt;parameter&gt;
                     &lt;inject bean="targetJNDI" /&gt;
                 &lt;/parameter&gt;
                 &lt;parameter&gt;/integration/jms/notificationRequestQueue&lt;/parameter&gt;
             &lt;/constructor&gt;
         &lt;/bean&gt;
  
         &lt;!-- JNDI is a Hashtable containing the JNDI properties required --&gt;
         &lt;!-- to connect to the sources and targets JMS resrouces         --&gt;
        &lt;bean name="sourceJNDI" class="java.util.Hashtable"&gt;
           &lt;constructor class="java.util.Map"&gt;
              &lt;map class="java.util.Hashtable" keyClass="java.lang.String"
                                               valueClass="java.lang.String"&gt;
                 &lt;entry&gt;
                    &lt;key&gt;java.naming.factory.initial&lt;/key&gt;
                    &lt;value&gt;org.jnp.interfaces.NamingContextFactory&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;java.naming.provider.url&lt;/key&gt;
                    &lt;value&gt;jnp://localhost:1099&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;java.naming.factory.url.pkgs&lt;/key&gt;
                    &lt;value&gt;org.jboss.naming:org.jnp.interfaces"&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;jnp.timeout&lt;/key&gt;
                    &lt;value&gt;5000&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;jnp.sotimeout&lt;/key&gt;
                    &lt;value&gt;5000&lt;/value&gt;
                 &lt;/entry&gt;
              &lt;/map&gt;
           &lt;/constructor&gt;
        &lt;/bean&gt;
        &lt;bean name="targetJNDI" class="java.util.Hashtable"&gt;
           &lt;constructor class="java.util.Map"&gt;
              &lt;map class="java.util.Hashtable" keyClass="java.lang.String"
                                               valueClass="java.lang.String"&gt;
                 &lt;entry&gt;
                    &lt;key&gt;java.naming.factory.initial&lt;/key&gt;
                    &lt;value&gt;org.jnp.interfaces.NamingContextFactory&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;java.naming.provider.url&lt;/key&gt;
                    &lt;value&gt;jnp://TARGET-URL.example.com:1099&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;java.naming.factory.url.pkgs&lt;/key&gt;
                    &lt;value&gt;org.jboss.naming:org.jnp.interfaces"&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;jnp.timeout&lt;/key&gt;
                    &lt;value&gt;5000&lt;/value&gt;
                 &lt;/entry&gt;
                 &lt;entry&gt;
                    &lt;key&gt;jnp.sotimeout&lt;/key&gt;
                    &lt;value&gt;5000&lt;/value&gt;
                 &lt;/entry&gt;
              &lt;/map&gt;
           &lt;/constructor&gt;
        &lt;/bean&gt;
  </code></pre>
  
  <p>The queue definitions on CLIENT side hornetq-jms.xml:</p>
  
  <pre><code>&lt;configuration xmlns="urn:hornetq"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd"&gt;
  
     &lt;connection-factory name="NettyConnectionFactory"&gt;
        &lt;connectors&gt;
           &lt;connector-ref connector-name="netty"/&gt;
        &lt;/connectors&gt;
        &lt;entries&gt;
           &lt;entry name="/ConnectionFactory"/&gt;
           &lt;entry name="/XAConnectionFactory"/&gt;
        &lt;/entries&gt;
        &lt;xa&gt;true&lt;/xa&gt;
     &lt;/connection-factory&gt;
  
     &lt;queue name="DLQ"&gt;
        &lt;entry name="/queue/DLQ"/&gt;
     &lt;/queue&gt;
  
     &lt;queue name="ExpiryQueue"&gt;
        &lt;entry name="/queue/ExpiryQueue"/&gt;
     &lt;/queue&gt;
  
     &lt;queue name="notificationQueue"&gt;
        &lt;entry name="/jms/notificationRequestQueue"/&gt;
     &lt;/queue&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And on the MASTER side hornetq-jms.xml:</p>
  
  <pre><code>&lt;configuration xmlns="urn:hornetq"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd"&gt;
  
     &lt;connection-factory name="NettyConnectionFactory"&gt;
        &lt;connectors&gt;
           &lt;connector-ref connector-name="netty"/&gt;
        &lt;/connectors&gt;
        &lt;entries&gt;
           &lt;entry name="/ConnectionFactory"/&gt;
           &lt;entry name="/XAConnectionFactory"/&gt;
        &lt;/entries&gt;
        &lt;xa&gt;true&lt;/xa&gt;
     &lt;/connection-factory&gt;
     &lt;connection-factory name="NettyRemoteConnectionFactory"&gt;
        &lt;connectors&gt;
           &lt;connector-ref connector-name="netty-remote"/&gt;
        &lt;/connectors&gt;
        &lt;entries&gt;
           &lt;entry name="/integration/XAConnectionFactory"/&gt;
        &lt;/entries&gt;
        &lt;xa&gt;true&lt;/xa&gt;
     &lt;/connection-factory&gt;
  
     &lt;queue name="DLQ"&gt;
        &lt;entry name="/queue/DLQ"/&gt;
     &lt;/queue&gt;
  
     &lt;queue name="ExpiryQueue"&gt;
        &lt;entry name="/queue/ExpiryQueue"/&gt;
     &lt;/queue&gt;
  
     &lt;queue name="targetQueue"&gt;
        &lt;entry name="/integration/jms/notificationRequestQueue"/&gt;
     &lt;/queue&gt;
  
      &lt;topic name="unrelatedTopic"&gt;
          &lt;entry name="/topic/cacheFlushNotification"/&gt;
      &lt;/topic&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  For some reason, the bridge starts transfering messages if I stop and restart the bridge once both servers are completely deployed. This is a manual process, and I loathe to use a hack to periodically restart the bridge. I welcome any suggestions to this issue.</p>
  
  <p>I also improved the startup sequence by making the bridge depend on the queue it reads from - otherwise the bridge is started before the queue, causing errors to log.</p>