Pre-integrated Tomcat with ActiveMQApache TomEE is a distribution of Tomcat with fully integrated ActiveMQ. All integration steps detailed here have already been done. The stack supports injection of Topic, Queue and ConnectionFactory references as well as transactional sending and delivery. Something like the following works out of the box with no configuration: import javax.annotation.Resource; import javax.servlet.http.HttpServlet; import javax.jms.Topic; import javax.jms.Queue; import javax.jms.ConnectionFactory; public class MyServet extends HttpServlet { @Resource(name = "foo") private Topic fooTopic; @Resource(name = "bar") private Queue barQueue; @Resource private ConnectionFactory connectionFactory; Manually integrating Tomcat and ActiveMQNote, manually integrating ActiveMQ with Tomcat does allow for Topic, Queue, and ConnectionFactory injection but does not support transactional sending and delivery. You should go to Tomcat documentation and read JNDI Resources HOW-TO, especially part: Configure Tomcat's Resource Factory. ActiveMQ has ready JNDI resource factory for all its administered objects: ConnectionFactory and destinations. You must provide it as a parameter factory for your resources: <Context ...> ... <Resource name="jms/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory"/> <ResourceParams name="jms/ConnectionFactory"> <parameter> <name>factory</name> <value>org.activemq.jndi.JNDIReferenceFactory</value> </parameter> <parameter> <name>brokerURL</name> <value>vm://localhost</value> </parameter> <parameter> <name>brokerName</name> <value>LocalActiveMQBroker</value> </parameter> <parameter> <name>useEmbeddedBroker</name> <value>true</value> </parameter> </ResourceParams> ... </Context>
If you are using Tomcat 5.5 or later then try this instead...
<Context>
...
<Resource name="jms/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://localhost" brokerName="LocalActiveMQBroker"/>
....
</Context>
Also, don't forget to put ActiveMQ and dependent jars to tomcat shared lib directory. Creating destinations in Tomcat 5.5 or laterThis is completely untested but should work
<Context>
...
<Resource name="jms/someTopic" auth="Container" type="org.apache.activemq.command.ActiveMQTopic" description="my Topic"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="FOO.BAR"/>
<Resource name="jms/aQueue" auth="Container" type="org.apache.activemq.command.ActiveMQQueue" description="my Queue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" physicalName="FOO.BAR"/>
....
</Context>
|