Real-Time Messaging with Tomcat and ActiveMQ
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.