简体   繁体   中英

Integrating ActiveMQ with Tomcat

I am looking for tips on integrating activemq with tomcat.

My architecture looks like below where each app is running on a different jvm/machines,

producer app -> tomcat (activemq) -> consumer app

The consumers and producers should connect to activemq on a remote machine. I would also like to have the web console enabled.

First you should download and install ActiveMQ on remote machine, web console will be enabled by default.

Second you should configure each tomcat node.

Put activemq-all.jar (version 5.11 and higher, you can download here http://mvnrepository.com/artifact/org.apache.activemq/activemq-all ) into $TOMCAT_HOME/lib folder. 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:

Add to $TOMCAT_HOME/CONF/context.xml

<Resource name="jms/activemq-factory" 
        auth="Container" 
        type="org.apache.activemq.ActiveMQConnectionFactory" 
        description="JMS Connection Factory" 
        factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
        brokerURL="tcp://${broker.host}:${broker.port}" 
        brokerName="LocalActiveMQBroker" 
        useEmbeddedBroker="false"/>

<Resource name="jms/activemq-topic" 
            auth="Container" 
            type="org.apache.activemq.command.ActiveMQTopic" 
            factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
            physicalName="activemq-topic"/> 

replace broker.host and broker.port to real ActiveMQ parameters.

Now you can write consumers for acticvemq-topic. Thats all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM