activemq + spring 配置内置(内嵌)vm

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:amq="http://activemq.apache.org/schema/core"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.2.xsd
        http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd
        "
    default-lazy-init="false">
 
    <description>异步调用相关配置</description>
    
  <amq:broker useJmx="false" persistent="true">
      <amq:persistenceAdapter>
       <amq:amqPersistenceAdapter directory="d:/amq"/>
    </amq:persistenceAdapter>
    <amq:transportConnectors>
      <amq:transportConnector uri="vm://localhost" />
    </amq:transportConnectors>
  </amq:broker>
 
    <amq:queue id="queueDestination"  physicalName="test.queue"/>
    
    <amq:topic id="topicDestination"  physicalName="test.topic"/>
    
  <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost"/>
 
  <!-- Spring JMS Template -->
  <bean id="queueJmsTemplate" 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="defaultDestination" ref="queueDestination"/>  
  </bean>
 
   <bean id="topicJmsTemplate" 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="defaultDestination" ref="topicDestination"/>  
      <!-- 订阅发布模式 -->  
     <property name="pubSubDomain" value="true" />  
     <property name="receiveTimeout" value="10000" />  
  </bean>
 
  <bean id="receiveQueue1" class="cn.com.git.cbs.dao.activemq.MQQueueConsumerA"></bean>
 
   <bean id="receiveQueue2" class="cn.com.git.cbs.dao.activemq.MQQueueConsumerB"></bean>    
    
    
   <!-- 指明了jmsQueue队列的接收监听器  多个监听器监听同一个队列,-->    
    <bean id="listenerContainer"  
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
         <!-- 消息监听器,就是同时启动几个Listener实例来消费消息。 -->
        <property name="concurrentConsumers" value="2" />  
        <property name="connectionFactory" ref="jmsFactory"></property>  
        <property name="destination" ref="queueDestination"></property>  
        <property name="messageListener" ref="receiveQueue1"></property>  
    </bean>
    
    <bean id="listenerContainer2"  
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">  
        <property name="concurrentConsumers" value="2" />  
        <property name="connectionFactory" ref="jmsFactory"></property>  
        <property name="destination" ref="queueDestination"></property>  
        <property name="messageListener" ref="receiveQueue2"></property>  
    </bean>  
    
 
</beans>
 
 
 
 
 
 
 
 

猜你喜欢

转载自blog.csdn.net/liyongshun82/article/details/84771580