itstarting:IT進(jìn)行時(shí)

          想自己所想,做自己所愛

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            28 隨筆 :: 3 文章 :: 55 評(píng)論 :: 0 Trackbacks
           

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

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

           總體參考官方網(wǎng)站進(jìn)行整合,差點(diǎn)害死人,不停的出現(xiàn)各種配置錯(cuò)誤,后來經(jīng)過google查詢各種郵件列表,才發(fā)現(xiàn)xsd使用不當(dāng)。        

          <?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>

          這個(gè)才是正確的,兩點(diǎn):

          1、去掉:

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

          2、用這個(gè)而不是那個(gè):

          這個(gè):

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

          那個(gè):     
               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>



                  三、客戶端配置此處僅供參考,還未曾具體實(shí)戰(zhàn)確認(rèn)):
                  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、客戶端的配置需要實(shí)戰(zhàn)后進(jìn)行進(jìn)一步的確認(rèn)、更新;
              2、后期視情況增加一篇《Spring2.x與ActiveMQ5.0成功集成的心得(實(shí)戰(zhàn)篇)》


              主要參考:

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

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

          posted on 2008-01-20 23:41 IT進(jìn)行時(shí) 閱讀(3449) 評(píng)論(3)  編輯  收藏 所屬分類: Java Tips

          評(píng)論

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

          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,都可以用

          但還沒搞清楚這些配置文件之間的區(qū)別:(  回復(fù)  更多評(píng)論
            

          # re: Spring2.x與ActiveMQ5.0成功集成的心得(配置篇) 2008-01-21 13:13 IT進(jìn)行時(shí)
          我現(xiàn)在是先跑起來,之后再逐點(diǎn)優(yōu)化、調(diào)整。
          入門是第一步。  回復(fù)  更多評(píng)論
            

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

          主站蜘蛛池模板: SHOW| 志丹县| 汝阳县| 喀什市| 英德市| 武鸣县| 调兵山市| 许昌市| 云浮市| 卓尼县| 开远市| 阿合奇县| 五大连池市| 武冈市| 十堰市| 拜泉县| 静海县| 井陉县| 定西市| 长沙市| 临汾市| 奉节县| 商水县| 永年县| 永胜县| 杨浦区| 尼玛县| 连城县| 金塔县| 金门县| 甘孜| 齐齐哈尔市| 麦盖提县| 龙游县| 来安县| 莲花县| 大英县| 纳雍县| 宝鸡市| 荔波县| 武定县|