Child pages
  • Real-Time Messaging with Tomcat and ActiveMQ
Skip to end of metadata
Go to start of metadata

You can easily integrate the RealTime Messaging Module with Tomcat and ActiveMQ.
Below are the key steps in setting up this integration.

1. Setup RealTime Messaging Module.
You need to configure the server.properties configuration file of your application. The basic configuration of this file should be as follows:

---server.properties----
messaging.dispatcherImplementer: com.isomorphic.messaging.JMSMessageDispatcher
jndi.messaging.java.naming.factory.initial: org.apache.activemq.jndi.ActiveMQInitialContextFactory
jndi.messaging.java.naming.provider.url: tcp://hostname:61616
messaging.jms.context: _container_
messaging.jms.jndiPrefix:
messaging.jms.topicConnectionFactory: jms/ConnectionFactory

2. Configure Tomcat with ActiveMQ.
Configure the context.xml configuration file of your Tomcat server. This file is located at <HOME_TOMCAT>/conf/. Use this configuration if you are using Tomcat 5.5 or later.

---context.xml----
<Resource auth="Container"
name="jms/ConnectionFactory"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="tcp://localhost:61616"
useEmbeddedBroker="false"
brokerName="localhost"/>

<Resource auth="Container"
name="chatChannel"
type="org.apache.activemq.command.ActiveMQTopic"
description="JMS Topic"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="chatChannel"/>

3. Setup ActiveMQ.
For an independent installation, please refer to the getting started guide.
If you prefer to run ActiveMQ inside Tomcat, use the previous configuration and consider these settings:

---server.properties----
jndi.messaging.java.naming.provider.url: vm://localhost
---context.xml----
<Resource auth="Container"
name="jms/ConnectionFactory"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="vm://localhost"
useEmbeddedBroker="true"
brokerName="localhost"/>

However, when using the embedded option, you only need to add  the following jars to Tomcat's lib folder:
activemq-all-5.5.1.jar
slf4j-log4j12-1.5.11.jar
log4j-1.2.14.jar
slf4j-api-1.5.11.jar

4. Setup your application.
Add the activemq-all-5.5.1.jar library to your application.

This configuration was tested with Apache ActiveMQ v 5.5.1 and Tomcat v. 7.0.16.

1 Comment

  1. EDIT: this has been fixed: http://forums.smartclient.com/showthread.php?t=29843&page=2

     

    this configuration is working, with the embedded broker option (activeMQ 5.8 with Tomcat 7 on ubuntu/JRockit). 

    But, using visualvm, I see peaks in the number of activemq threads, peaks which, strangely enough, gets higher every time a single push operation is invoked. 

    An example of this trend: