创业的那些事儿-spring与activeMQ集成-queue消费者
<?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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><!-- failover 自动重连机制 --><bean id="targetConnectionFactory" value="failover:(tcp://localhost:61616)" /></bean><!-- 使用连接池 --><bean id="pooledConnectionFactory" ref="targetConnectionFactory" /><property name="maxConnections" value="10" /></bean><!-- 使用single connect (对于已经连接到MQ的线程始终使用同一条连接) --><bean id="connectionFactory"ref="pooledConnectionFactory" /></bean><bean id="destination" ref="connectionFactory" /><property name="destination" ref="destination" /><property name="messageListener" ref="messageListener" /></bean></beans>
对应实现的listener
package com.yysns.feed;import javax.jms.Message;import javax.jms.MessageListener;public class FeedMessageListener implements MessageListener {@Overridepublic void onMessage(Message feedMessage) { //TODO}}

ps:此代码来源于www.yuge.com开发中, 由于保密的问题故不能贴出太多代码,请见谅