itstarting:IT進行時

          想自己所想,做自己所愛

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            28 隨筆 :: 3 文章 :: 55 評論 :: 0 Trackbacks
           

          ActiveMQ 5.0的文檔實在是太少了,尤其是集成Spring2.x方面更少。

                  下面是配置方面的心得:
                  一、服務器端配置:

           總體參考官方網站進行整合,差點害死人,不停的出現各種配置錯誤,后來經過google查詢各種郵件列表,才發現xsd使用不當。        

          <?xml version="1.0" encoding="UTF-8"?>
          <beans 
            
          xmlns="http://www.springframework.org/schema/beans" 
            xmlns:amq
          ="http://activemq.org/config/1.0"
            xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"
          >


          </beans>

          這個才是正確的,兩點:

          1、去掉:

          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

          2、用這個而不是那個:

          這個:

                     http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd

          那個:     
               http://activemq.apache.org/snapshot-schema/activemq-core-5.0-SNAPSHOT.xsd


                  完整的配置如下:        
                  applicationContext-activeMQ.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <beans 
            
          xmlns="http://www.springframework.org/schema/beans" 
            xmlns:amq
          ="http://activemq.org/config/1.0"
            xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"
          >

            
          <amq:broker useJmx="true" persistent="true"> 
              
          <amq:persistenceAdapter> 
                  
          <amq:jdbcPersistenceAdapter dataSource="#mysql-ds"/> 
                
          </amq:persistenceAdapter> 
              
          <amq:transportConnectors> 
                 
          <amq:transportConnector uri="tcp://localhost:0"/> 
              
          </amq:transportConnectors> 
             
          </amq:broker>
            
            
          <!-- MySql DataSource Setup -->
            
          <bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
              
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
              
          <property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
              
          <property name="username" value="activemq"/>
              
          <property name="password" value="activemq"/>
              
          <!--
              <property name="poolPreparedStatements" value="true"/>
          -->
            
          </bean>
          </beans>


                  二、web.xml配置: 

              <!--activeMQ-->
              
          <context-param>
                  
          <param-name>contextConfigLocation</param-name>
                  
          <param-value>
                      /WEB-INF/applicationContext-activeMQ.xml 
                      /WEB-INF/applicationContext-jms.xml 
                  
          </param-value>
              
          </context-param>

              
          <listener>
                  
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
              
          </listener>



                  三、客戶端配置此處僅供參考,還未曾具體實戰確認):
                  applicationContext-jms.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <beans 
            
          xmlns="http://www.springframework.org/schema/beans" 
            xmlns:amq
          ="http://activemq.org/config/1.0"
            xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"
          >
            
          <!-- ActiveMQ destinations to use  -->
            
          <amq:queue id="destination"  physicalName="org.apache.activemq.spring.Test.spring.embedded"/>

            
          <!-- JMS ConnectionFactory to use, configuring the embedded broker using XML -->
            
          <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost"/>  
            
          <!-- Spring JMS Template -->
            
          <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
              
          <property name="connectionFactory">
                
          <!-- lets wrap in a pool to avoid creating a connection per send -->
                
          <bean class="org.springframework.jms.connection.SingleConnectionFactory">
                  
          <property name="targetConnectionFactory">
                    
          <ref bean="jmsFactory" />
                  
          </property>
                
          </bean>
              
          </property>
              
          <property name="messageConverter">
                  
          <ref bean="dynamicMessageConverter"/>
              
          </property>
            
          </bean>
            
            
          <bean id="dynamicMessageConverter" class="com.tuanzi.message.mq.impl.DynamicMessageConverter"/>  

            
          <bean id="consumerJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
              
          <property name="connectionFactory">
                  
          <ref bean="jmsFactory"/>
              
          </property>
              
          <property name="messageConverter">
                  
          <ref bean="dynamicMessageConverter"/>
              
          </property>
              
          <property name="receiveTimeout">
                  
          <value>10000</value>
              
          </property>
            
          </bean>

            
          <!-- a sample POJO which uses a Spring JmsTemplate -->
            
          <bean id="simpleMessageProducer" class="com.tuanzi.message.mq.impl.SimpleMessageProducer">
              
          <property name="jmsTemplate">
                
          <ref bean="jmsTemplate"></ref>
              
          </property>
              
          <property name="destination">
                
          <ref bean="destination" />
              
          </property>
            
          </bean>

            
          <!-- a sample POJO consumer -->
            
          <bean id="simpleMessageConsumer" class="com.tuanzi.message.mq.impl.SimpleMessageConsumer">
              
          <property name="jmsTemplate" ref="consumerJmsTemplate"/>
              
          <property name="destination" ref="destination"/>
            
          </bean>
          </beans>


              TODO:
              1、客戶端的配置需要實戰后進行進一步的確認、更新;
              2、后期視情況增加一篇《Spring2.x與ActiveMQ5.0成功集成的心得(實戰篇)》


              主要參考:

          http://activemq.apache.org/spring-support.html

          http://activemq.apache.org/xml-reference.html

          posted on 2008-01-20 23:41 IT進行時 閱讀(3441) 評論(3)  編輯  收藏 所屬分類: Java Tips

          評論

          # re: Spring2.x與ActiveMQ5.0成功集成的心得(配置篇) 2008-01-21 11:23 genjuro
          我是直接從它的svn取測試的源碼和配置文件來用

          https://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/spring/
          https://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/test/resources/

          試過spring.xml,spring-queue.xml和spring-embedded.xml,都可以用

          但還沒搞清楚這些配置文件之間的區別:(  回復  更多評論
            

          # re: Spring2.x與ActiveMQ5.0成功集成的心得(配置篇) 2008-01-21 13:13 IT進行時
          我現在是先跑起來,之后再逐點優化、調整。
          入門是第一步。  回復  更多評論
            

          # re: Spring2.x與ActiveMQ5.0成功集成的心得(配置篇) 2008-01-30 09:59 yahoo
          把代碼發出來啊  回復  更多評論
            

          主站蜘蛛池模板: 吉首市| 榆社县| 丹阳市| 肥城市| 固阳县| 图木舒克市| 怀宁县| 徐州市| 邯郸县| 大新县| 郧西县| 瑞昌市| 交城县| 贡觉县| 嵊泗县| 米林县| 鄂州市| 岳普湖县| 嘉义县| 武平县| 塔城市| 通山县| 丁青县| 定州市| 浙江省| 若尔盖县| 阿合奇县| 香河县| 轮台县| 迭部县| 滦平县| 乌鲁木齐市| 新巴尔虎右旗| 通山县| 卢氏县| 四子王旗| 抚松县| 镇巴县| 武鸣县| 邢台市| 湘阴县|