码迷,mamicode.com
首页 > 编程语言 > 详细

Spring整合ActiveMQ

时间:2018-07-18 14:05:37      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:对象   无限   table   nec   点对点   监听器   def   context   apach   

applicationContext.xml配置文件:

<!-- 属性文件配置 -->    
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    
    <property name="locations">    
        <list>    
            <value>classpath:jdbc.properties</value>    
        </list>    
    </property>    
</bean>    
<!-- dbcp -->    
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"    
      destroy-method="close">    
    <property name="driverClassName" value="${driverClassName}" />    
    <property name="url" value="${url}" />    
    <property name="username" value="${username}" />    
    <property name="password" value="${password}" />    
    <!-- 连接初始值,连接池启动时创建的连接数量的初始值  默认值是0 -->    
    <property name="initialSize" value="3" />    
    <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请  默认值是0 -->    
    <property name="minIdle" value="3" />    
    <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 ,0时无限制  默认值是8 -->    
    <property name="maxIdle" value="5" />    
    <!-- 连接池的最大值,同一时间可以从池分配的最多连接数量,0时无限制   默认值是8 -->    
    <property name="maxActive" value="15" />    

    <property name="minEvictableIdleTimeMillis" value="1800000" />    
    <property name="numTestsPerEvictionRun"  value="3"/>    
    <property name="testOnBorrow" value="true"/>    
    <property name="testWhileIdle" value="true"/>    
    <property name="testOnReturn" value="true"/>    
    <property name="validationQuery" value="SELECT 1"/>    
</bean>    


<!-- 1.jedisPoolConfig配置对象 -->    
<!-- 暂时用的本地redis数据库 -->    
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">    
    <!-- 最大连接数 -->    
    <property name="maxTotal" value="20"></property>    
    <!-- 空闲最大连接数 -->    
    <property name="maxIdle" value="5"></property>    
</bean>    

<!-- 2.jedisPool连接池对象 -->    
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">    
    <!-- 使用构造方法的形式注入数据 -->    
    <constructor-arg index="0" ref="jedisPoolConfig"></constructor-arg>    
    <constructor-arg index="1" type="java.lang.String" value="127.0.0.1"></constructor-arg>    
    <constructor-arg index="2" value="6379"></constructor-arg>    
</bean>    

<bean id="autoProxyCreator"    
    class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">    
    <property name="proxyTargetClass">    
        <value>true</value>    
    </property>    
</bean>    


<!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供 -->    
<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">    
    <property name="brokerURL" value="tcp://localhost:61616" />    
</bean>    
<bean id="connectionFactory"    
    class="org.springframework.jms.connection.SingleConnectionFactory">    
    <property name="targetConnectionFactory" ref="targetConnectionFactory" />    
</bean>    
<!--这个是队列目的地,点对点的 -->    
<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">    
    <constructor-arg>    
        <value>queue</value>    
    </constructor-arg>    
</bean>    
<!--这个是主题目的地,一对多的    
<bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">    
    <constructor-arg value="topic" />    
</bean> -->    

<!-- 配置JMS模板(Queue),Spring提供的JMS工具类,它发送、接收消息。 -->    
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">    
    <property name="connectionFactory" ref="connectionFactory" />    
    <property name="defaultDestination" ref="queueDestination" />    
    <property name="receiveTimeout" value="10000" />    
    <!-- true是topic,false是queue,默认是false,此处显示写出false -->    
    <property name="pubSubDomain" value="false" />    
</bean>    
<!-- 配置监听器 -->    
<bean id="myMessageListener" class="com.alibaba.otter.canal.example.listener.MyMessageListener" />    
<!-- 消息监听容器 -->    
<bean id="jmsContainer"    
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">    
    <property name="connectionFactory" ref="connectionFactory" />    
    <property name="destination" ref="queueDestination" />    
    <property name="messageListener" ref="myMessageListener" />    
</bean>    

Spring整合ActiveMQ

标签:对象   无限   table   nec   点对点   监听器   def   context   apach   

原文地址:https://www.cnblogs.com/zhangtianshi/p/9327774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!