Spring 使用ActiveMQ 收发消息实例
Spring配置文件如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans> <!-- 配置ActiveMQ 连接 --> <bean id="jmsConnectionFactory" value="tcp://localhost:61616" /> <property name="userName" value="admin" /> <property name="password" value="password" /> </bean> <!-- 可配置ActiveMQ 连接池 需要引入 commons-pool--> <bean id="pooledJmsConnectionFactory" destroy-method="stop"> <property name="connectionFactory" ref="jmsConnectionFactory" /> </bean> <!-- 配置消息目的地 --> <bean id="cscoDest" /> </bean> <bean id="orclDest" /> </bean> <!-- 配置消息监听器 --> <bean id="portfolioListener" ref="jmsConnectionFactory" /> <property name="destination" ref="cscoDest" /> <property name="messageListener" ref="portfolioListener" /> </bean> <!-- Spring DMLC --> <bean id="orclConsumer" ref="jmsConnectionFactory" /> <property name="destination" ref="orclDest" /> <property name="messageListener" ref="portfolioListener" /> </bean> <!-- 发送消息 --> <!-- Spring JMS Template template.send(destination, getStockMessageCreator(destination)); jmsTemplate使用send方法发送消息,该方法需要一个MessageCreator接口实现类 JmsTemplate需要一个连接工厂. --> <bean id="jmsTemplate" ref="pooledJmsConnectionFactory" /> </bean> <bean id="stockPublisher" ref="jmsTemplate" /> <property name="destinations"> <list> <ref local="cscoDest" /> <ref local="orclDest" /> </list> </property> </bean></beans>
?
?