|
该帖已经被评为良好帖
|
|
|---|---|
| 作者 | 正文 |
|
时间:2006-12-04
作者:cctvx1,calvin
1.概述1.1 JMS与ActiveMQ特性JMS始终在JavaEE五花八门的协议里,WebService满天飞的时候占一位置,是因为:
ActiveMQ
1.2 SpringSide 的完全POJO的JMS方案 SpringSide 2.0 全部代码于examples\bookstore\src\java\org\springside\bookstore\components\activemq 目录中。 一个JMS场景通常需要三者参与:
SpringSide 2.0
2.引入ActiveMQ的XSDActiveMQ4.1 响应Spring 2.0号召,支持了引入XML Schema namespace的简单配置语法,简化了配置的语句。 在ApplicationContext.xml(Spring的配置文件)中引入ActiveMQ的XML Scheam 配置文件),如下: <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.xsd http://activemq.org/config/1.0 http://people.apache.org/repository/org.apache.activemq/xsds/activemq-core-4.1-incubator-SNAPSHOT.xsd"> 由于ActiveMQ4.1 SnapShot的那个XSD有部分错误,因此使用的是自行修改过的XSD。 先在ClassPath根目录放一个修改过的activemq-core-4.1-incubator-SNAPSHOT.xsd。 在ClassPath 下面建立META-INF\spring.schemas 内容如下。这个spring.schemas是spring自定义scheam的配置文件,请注意"http:\://"部分写法 http\://people.apache.org/repository/org.apache.activemq/xsds/activemq-core-4.1-incubator-SNAPSHOT.xsd=/activemq-core-4.1-incubator-SNAPSHOT.xsd
3. 配置方案3.1 基础零件1. 配置ActiveMQ Broker 暂时采用在JVM中嵌入这种最简单的模式, 当spring初始化时候,ActiveMQ embedded Broker 就会启动了。 <!-- lets create an embedded ActiveMQ Broker --> <amq:broker useJmx="false" persistent="false"> <amq:transportConnectors> <amq:transportConnector uri="tcp://localhost:0"/> </amq:transportConnectors> </amq:broker> 2. 配置(A)ConnectionFactory 由于前面配置的Broker是JVM embedded 所以URL为:vm://localhost <!-- ActiveMQ connectionFactory to use --> <amq:connectionFactory id="jmsConnectionFactory" brokerURL="vm://localhost"/> 3 配置(B)Queue <!-- ActiveMQ destinations to use --> <amq:queue name="destination" physicalName="org.apache.activemq.spring.Test.spring.embedded"/> 4. 配置(C)Converter 配置Conveter,使得Producer能够直接发送Order对象,而不是JMS的Message对象。 <!-- OrderMessage converter --> <bean id="orderMessageConverter" class="org.springside.bookstore.components.activemq.OrderMessageConverter"/> 3.2 发送端1 配置JmsTemplate Spring提供的Template,绑定了(A)ConnectionFactory与(C)Converter。 <!-- Spring JmsTemplate config --> <bean id="jmsTemplate" 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="jmsConnectionFactory"/> </bean> </property> <!-- custom MessageConverter --> <property name="messageConverter" ref="orderMessageConverter"/> </bean> 2.Producer 消息发送者,使用JmsTemplate发送消息,绑定了JmsTemplate (含A、C)与(B)Queue。 <!-- POJO which send Message uses Spring JmsTemplate,绑定JMSTemplate 与Queue --> <bean id="orderMessageProducer" class="org.springside.bookstore.components.activemq.OrderMessageProducer"> <property name="template" ref="jmsTemplate"/> <property name="destination" ref="destination"/> </bean> 3.3 接收端1.接收处理者(MDP) 使用Spring的MessageListenerAdapter,指定负责处理消息的POJO及其方法名,绑定(C)Converter。 <!-- Message Driven POJO (MDP),绑定Converter --> <bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter"> <constructor-arg> <bean class="org.springside.bookstore.components.activemq.OrderMessageConsumer"> <property name="mailService" ref="mailService"/> </bean> </constructor-arg> <!-- may be other method --> <property name="defaultListenerMethod" value="sendEmail"/> <!-- custom MessageConverter define --> <property name="messageConverter" ref="orderMessageConverter"/> </bean> 2. listenerContainer 负责调度MDP, 绑定(A) connectionFactory, (B)Queue和MDP。 <!-- this is the attendant message listener container --> <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsConnectionFactory"/> <property name="destination" ref="destination"/> <property name="messageListener" ref="messageListener"/> </bean> 互相绑定的关系有点晕,发送端和接收端都以不同形式绑定了(A) connectionFactory, (B)Queue和 (C)Converter. 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2006-12-04
全变成xml了,呵呵.
|
|
| 返回顶楼 | |
|
时间:2006-12-04
使用过程中还会出现很多问题,比如服务器重起后会受到之前收到的消息。。。。。
|
|
| 返回顶楼 | |
|
时间:2006-12-04
amonlei 写道 使用过程中还会出现很多问题,比如服务器重起后会受到之前收到的消息。。。。。
mq的消息队列可以配置保存在内存中,也可以是保存在数据库中。如果是保存在数据库中,如果消息还没有被消费的话,重启服务器消息还是存在的 |
|
| 返回顶楼 | |
|
时间:2006-12-04
i don't like the way in which spring and lingo encapsulate jms.
jms is so lite-weighted that it's not necessary to put so many wrappers around it. btw, active_mq's performance is much worse than that of tibco's impl, which is a real jms service provider rather than a toy. >> 使用过程中还会出现很多问题,比如服务器重起后会受到之前收到的消息。。。。。 have u read jms spec b4 posting? |
|
| 返回顶楼 | |
|
时间:2006-12-14
jigsaw 写道 i don't like the way in which spring and lingo encapsulate jms. i do . 每次做了消费确认。。都一样。。官方的例子就是如此。。
jms is so lite-weighted that it's not necessary to put so many wrappers around it. btw, active_mq's performance is much worse than that of tibco's impl, which is a real jms service provider rather than a toy. >> 使用过程中还会出现很多问题,比如服务器重起后会受到之前收到的消息。。。。。 have u read jms spec b4 posting? |
|
| 返回顶楼 | |
|
时间:2006-12-14
jigsaw 写道 btw, active_mq's performance is much worse than that of tibco's impl, which is a real jms service provider rather than a toy. Tibco是不是开源的?可以免费使用吗? |
|
| 返回顶楼 | |
|
时间:2006-12-26
郁闷,跑了一下spring例子,结果activemq的存储转发功能没有了
|
|
| 返回顶楼 | |
浏览 8045 次









