These instructions create a configuration that matches what is distributed with BlazeDS. You should be able to integrate Apache ActiveMQ 4.1.1 with earlier versions of Tomcat and you should also be able to integrate newer versions of ActiveMQ with Tomcat 6.0.x, but none of these configurations have been tested. These instructions require that you have a valid Apache Ant installation.

Complete the following steps to integrate ActiveMQ with your own installation of Tomcat 6.0.x:

  1. Download ActiveMQ 4.1.1 from http://activemq.apache.org/.
  2. Download and install the ActiveMQ distribution following the instructions provided on the ActiveMQ website.
  3. ActiveMQ ships with an example that contains the JAR files and configuration settings that work with a web application deployment. Build the example by opening a command prompt, changing to the activemq_root/example directory and running the following command to build the example:
    ant war
  4. In the tomcat_root/lib directory, create a new directory called activemq4.1.1. Copy the contents of the activemq_root/example/target/activemq-web/WEB-INF/lib directory to this new directory.
  5. Open the catalina.properties file from the tomcat_install/conf directory in a text editor. Modify the common.loader property by adding the following to the list of comma-seperated paths:
    ${catalina.home}/lib/activemq4.1.1/*.jar
  6. Modify your BlazeDS web application to start an ActiveMQ message broker when the web application starts. To do this, open the WEB-INF/web.xml file for your web application in a text editor. Add the following context-param and listener elements. Make sure you put them in the correct location within the web.xml. The order of these must match the web-app dtd.
    <context-param>
        <param-name>brokerURI</param-name>
    
        <param-value>/WEB-INF/activemq.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.apache.activemq.web.SpringBrokerContextListener</listener-class>
    </listener>
    
  7. In the WEB-INF directory of your web application create a new file called activemq.xml. Open the file in a text editor and add the following text:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans>
    	<broker useJmx="true" persistent="false" xmlns="http://activemq.org/config/1.0" brokerName="myBroker">
    
    		<transportConnectors>
    			<transportConnector name="default" uri="tcp://localhost:61716"/>
    		</transportConnectors>
    	</broker>
    </beans>
    

    This starts an ActiveMQ message broker with a broker name of myBroker listening for requests on the localhost network interface at port 61716.

  8. Add the ActiveMQ connection factories and any JMS Topics and Queues you want to use to JNDI. The easiest way to do this in Tomcat 6.0.x is to create a context file for your web application and put the settings in there. To do this, create a new file in the tomcat_install/conf/Catalina/localhost directory. If the Catalina/localhost directory does not exit already create it now. The new file that you create should have the same name as the web application with a .xml extension. For example, if your BlazeDS web application is named samples the Tomcat context file should be named samples.xml. For more information on context files, refer to your Tomcat documentation. Once you have created the file, open it in a text editor. Add the following contents to the file, replacing the example topic and queue shown here with your own topics and queues:
    <Context privileged="true" antiResourceLocking="false" antiJARLocking="false" reloadable="true">
    
        <Resource name="jms/flex/TopicConnectionFactory"
                    type="org.apache.activemq.ActiveMQConnectionFactory"
                    description="JMS Connection Factory"
                    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                    brokerURL="tcp://localhost:61716"
    
                    brokerName="myBroker"/>
     	<Resource name="jms/topic/flex/simpletopic"
                    type="org.apache.activemq.command.ActiveMQTopic"
                    description="my Topic"
    
                    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                    physicalName="FlexTopic"/>
    	<Resource name="jms/flex/QueueConnectionFactory"
                    type="org.apache.activemq.ActiveMQConnectionFactory"
    
                    description="JMS Connection Factory"
                    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                    brokerURL="tcp://localhost:61716"
                    brokerName="myBroker"/>
    
        <Resource name="jms/queue/flex/simplequeue"
                    type="org.apache.activemq.command.ActiveMQQueue"
                    description="my Queue"
                    factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                    physicalName="FlexQueue"/>                
        <Valve className="flex.messaging.security.TomcatValve"/>
    
    </Context>
    
  9. Start your Tomcat server. The ActiveMQ message broker should start listening for messages on port 61716 and you should be able to send messages to and receive message from the JMS topics and queues you have configured. For more information about configuring and using ActiveMQ, please refer to the ActiveMQ documentation which is available on http://activemq.apache.org/.
posted on 2009-09-20 23:15  sky100  阅读(449)  评论(0编辑  收藏  举报