spring jms使用activemq 持久订阅topic

最近在学spring. 在学习到spring集成jms的时候碰到了topic持久订阅的问题。几经努力,终于找到了配置方法。在此分享下。如有更好的方法,望分享下。配置文件如下:
applicationContext-sender.xml
-----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>

<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"></property>
</bean>
</property>
</bean>

<bean id="dest" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="mydest"></constructor-arg>
</bean>
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"></property>
<property name="defaultDestination" ref="dest"></property>
<property name="pubSubDomain" value="true"></property> </bean>
<bean id="messageSender" class="spring.MessageSender">
<property name="jmsTemplate" ref="jmsTemplate"></property>
</bean>
</beans>
-------------------------------------------------------------
applicationContext-receiver.xml
-------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"></property>
</bean>
</property>
</bean>

<bean id="dest" class="org.apache.activemq.command.ActiveMQTopic">
<property name="physicalName" value="mydest?consumer.retroactive=true&amp;consumer.pref etchSize=10"></property> </bean>
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"></property>
<property name="defaultDestination" ref="dest"></property>
</bean>
<bean id="messageReceiver" class="spring.MessageReceiver">
<property name="jmsTemplate" ref="jmsTemplate"></property>
</bean>

</beans>

你可能感兴趣的:(spring,bean,xml,jms,activemq)