<?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>
哦了,上面是配置监听来取queue队列,需求是多个监听来取消息,同样一条消息只能被一个监听客户端获取,所以配置成queue.
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/industrynews/13695.html