Search code examples
jmstomcat7activemq-classicapache-tomee

Tomcat configuration to connect to remote ActiveMQ instance


Problem Statement: I am looking for help to expose a JMS connection factory to a remote ActiveMQ instance (listening on tcp) as a container resource in Tomcat7 so that the Web Applications deployed on Tomcat7 can access it.

My configuration: I have a Tomee and a Tomcat7 instance running on the server. The Tomee in host to the ActiveMQ with broker configured to listen to tcp wireformat connection (tomee.xml below):

 <?xml version="1.0" encoding="UTF-8"?>
 <tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->
    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  broker:(tcp://10.173.80.42:61619)
        ServerUrl       =  tcp://10.173.80.42:61619
    </Resource>

    <Resource id="jms/ConnectionFactory" type="javax.jms.ConnectionFactory">
        ResourceAdapter = MyJmsResourceAdapter
    </Resource>

    <Container id="MyJmsMdbContainer" type="MESSAGE">
        ResourceAdapter = MyJmsResourceAdapter
    </Container>

   <Resource id="myqueue" type="javax.jms.Queue"/>


  <!-- activate next line to be able to deploy applications in apps -->
  <Deployments dir="apps" />
</tomee>

In my Tomcat7 instance, I have configured the server.xml as:

<Resource name="jms/ConnectionFactory"
          auth="Container"
          type="org.apache.activemq.ActiveMQConnectionFactory"
          description="JMS Connection Factory"
          factory="org.apache.activemq.jndi.JNDIReferenceFactory"
          brokerURL="tcp://10.173.80.42:61619?soTimeout=60000"
          brokerName="ActiveMQStageBroker"
          useEmbeddedBroker="false" />

<Resource name="myQueue"
          auth="Container"
          type="org.apache.activemq.command.ActiveMQQueue"
          proxy-interface="javax.jms.Queue"
          description="My Queue"
          factory="org.apache.activemq.jndi.JNDIReferenceFactory"
          physicalName="myQueue" />

And I have placed activemq-all-5.12.0.jar in the Tomcat7 shared library folder. I have also made the relevant references in the context.xml file under the Web applications META-INF folder and for an added measure created resource-ref in the web.xml (essentially grasping for straws here)

My Observations: When I initiate the action that triggers communication with the ActiveMQ, I see the following entries in my log file:

2016-07-19 10:40:07,659 [system         ] DEBUG WireFormatNegotiator           - Sending: WireFormatInfo { version=11, properties={MaxFrameSize=9223372036854775807, CacheSize=1024, CacheEnabled=true, Host=10.173.80.42, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
2016-07-19 10:40:07,666 [.42:61619@45620] DEBUG InactivityMonitor              - Using min of local: WireFormatInfo { version=11, properties={MaxFrameSize=9223372036854775807, CacheSize=1024, CacheEnabled=true, Host=10.173.80.42, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]} and remote: WireFormatInfo { version=10, properties={CacheSize=1024, MaxFrameSize=9223372036854775807, CacheEnabled=true, SizePrefixDisabled=false, TcpNoDelayEnabled=true, MaxInactivityDurationInitalDelay=10000, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
2016-07-19 10:40:07,667 [.42:61619@45620] DEBUG WireFormatNegotiator           - Received WireFormat: WireFormatInfo { version=10, properties={CacheSize=1024, MaxFrameSize=9223372036854775807, CacheEnabled=true, SizePrefixDisabled=false, TcpNoDelayEnabled=true, MaxInactivityDurationInitalDelay=10000, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
2016-07-19 10:40:07,667 [.42:61619@45620] DEBUG WireFormatNegotiator           - tcp:///10.173.80.42:61619@45620 before negotiation: OpenWireFormat{version=11, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false, maxFrameSize=9223372036854775807}
2016-07-19 10:40:07,668 [.42:61619@45620] DEBUG WireFormatNegotiator           - tcp:///10.173.80.42:61619@45620 after negotiation: OpenWireFormat{version=10, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false, maxFrameSize=9223372036854775807}
2016-07-19 10:40:08,834 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:08,836 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:08,834 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:08,836 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:18,835 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:18,835 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:27,667 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:27,668 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:28,813 [ ReadCheckTimer] DEBUG AbstractInactivityMonitor      - 30000ms elapsed since last read check.
2016-07-19 10:40:28,834 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:28,834 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:37,667 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:37,668 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:38,834 [WriteCheckTimer] DEBUG AbstractInactivityMonitor      - WriteChecker: 10000ms elapsed since last write check.
2016-07-19 10:40:38,835 [yMonitor Worker] DEBUG AbstractInactivityMonitor      - Running WriteCheck[tcp://10.173.80.42:61619]
2016-07-19 10:40:47,667 [ ReadCheckTimer] DEBUG AbstractInactivityMonitor      - 30000ms elapsed since last read check.

Also, when I look at my queue's EnqueueCount and DequeueCount, I see they have not changed.

Since the log indicates that my Tomcat7 Container actually received information from the remote instance (referring to "Received Wireformat: ..."), the two instances can communicated. But why am I unable to send the data?

Addendum: Same web app when deployed in Tomee instance that hosts the ActiveMQ can communicate seamlessly with the Queue.

Appreciate any thoughts on what I may be doing wrong or options I can try on both Tomee and Tomcat7 end.

Thanks in advance!


Solution

  • After countless hours spent trying to get the above mentioned configuration to work, it turned out to be:

    1. JNDI lookup issue;
    2. Compounded by the developer who logged exception at Debug level, instead of Error level (Thanks man!).

    Anyways, with all of those sorted, here is what I did find:

    1. The above mentioned configuration works fine, where the ActiveMQ is configured to run as part of Tomee container and have Connection broker on Tomcat7 exposed as Globally shared resource to WebApps deployed within it (know your JNDI!).

    2. I also was able to use the configuration suggested by @JonathanS.Fisher. I was able to bring up the ActiveMQ as a Stand-alone instance and have my apps hosted on Tomcat7 and Tomee connect to it.

    Hope this helps anyone stuck in similar situation.

    Cheers