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进行时 阅读(3422) 评论(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
把代码发出来啊  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: