论坛首页 Java企业应用论坛

spring jms同时使用queue和持久topic订阅

浏览 5436 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-07   最后修改:2010-02-01
(1)spring配置文件
<?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://people.apache.org/repository/org.apache.activemq/xsds/activemq-core-4.2-incubator-SNAPSHOT.xsd">

    <bean id="connectionFactory"
        class="org.apache.activemq.spring.ActiveMQConnectionFactory">
		<property name="brokerURL" value="tcp://195.2.199.169:61616"/>
		<property name="useAsyncSend" value="true"/>
   	</bean>

	<bean id="topicListenConnectionFactory"
        class="org.apache.activemq.spring.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://195.2.199.169:61617"/>
        <property name="clientID" value="clientId_007"/>
    </bean>
	
    <!-- 消息队列监听者(MDP) -->
    <bean id="queueMsgListener" class="com.cdmcs.oa.jms.MagMessageListener"/>
	<!-- 消息主题监听者(MDP) -->
    <bean id="topicMsgListener" class="com.cdmcs.oa.jms.MagTopicMsgListener"/>
	
	<!--定义消息队列-->
	<bean id="myQueue" class="org.apache.activemq.command.ActiveMQQueue">
          <constructor-arg value="Queue.007"/>
    </bean>
	<!--定义订阅主题-->
    <bean id="myTopic"  class="org.apache.activemq.command.ActiveMQTopic">
  		  <constructor-arg value="basicInfo.topic"/>
  	</bean>

	<!-- 监听自己的消息 -->
    <bean id="myMsgQueuelistenerContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="concurrentConsumers" value="1"/>
        <property name="maxConcurrentConsumers" value="1"/>
        <property name="destination" ref="myQueue"/>
        <property name="messageListener" ref="queueMsgListener"/>
        <property name="receiveTimeout" value="10000"/>
        
        <property name="taskExecutor" ref="taskExecutor" />
        <!--0:CACHE_NONE,1:CACHE_CONNECTION,2:CACHE_SESSION,3:CACHE_CONSUMER,4:CACHE_AUTO-->
        <property name="cacheLevel" value="0"/>
    </bean>
    
    <!--监听公共消息(持久订阅者)-->
    <bean id="myMsgTopicListenerContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="topicListenConnectionFactory"/>
        <property name="pubSubDomain" value="true"/>
        
        <property name="concurrentConsumers" value="1"/>
		<property name="maxConcurrentConsumers" value="1"/>
        <property name="receiveTimeout" value="10000"/>
        <property name="destination" ref="myTopic" />
        
        <property name="subscriptionDurable" value="true"/>
        <property name="clientId" value="clientId_007"/>
        <property name="durableSubscriptionName" value="clientId_007"/>
        
        <property name="messageListener" ref="topicMsgListener"/>
        <property name="taskExecutor" ref="taskExecutor" />
        <property name="cacheLevel" value="0"/>
     </bean>
    
    <!--DefaultMessageListenerContainer默认的线程池支持-->
    <bean id="taskExecutor" 
		class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
    
    <bean id="jmsQueueTemplate"
        class="org.springframework.jms.core.JmsTemplate102">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="messageConverter" ref="simpleConverter"/>
       	<property name="sessionTransacted" value="true"/>
        <property name="receiveTimeout" value="10000"/>
    </bean>
    
    <bean id="jmsTopicTemplate"
        class="org.springframework.jms.core.JmsTemplate102">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="messageConverter" ref="simpleConverter"/>
        <property name="pubSubDomain" value="true"/>
        <property name="sessionTransacted" value="true"/>
        <property name="receiveTimeout" value="10000"/>
    </bean>
  
    <bean id="simpleConverter"
        class="org.springframework.jms.support.converter.SimpleMessageConverter"/>


</beans>
   
(2)activemq配置
    <!-- The transport connectors ActiveMQ will listen to -->
    <transportConnectors>
       <transportConnector name="myQueue" uri="tcp://localhost:61616"/>
       <transportConnector name="myTopic" uri="tcp://localhost:61617"/>
    </transportConnectors>
      
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics