Spring 2.5 + ActiveMQ 5.2.0 Embedded Broker实现

[size=medium]主[/size]要的代码实现在上一篇文章,而本篇文章重点是说明 ActiveMQ 5.2.0 Embedded Broker实现。
另外,打开 activemq-all-5.2.0.jar 修改 spring.schemas文件,在文件最后添加
\://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd = activemq.xsd
这样应用系统启动时就不用到官方网站读 activemq-core-5.2.0.xsd 文件了,省了好多时间~

首先新建 applicationContext-jms.xml

<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd"
default-lazy-init="true">
<description>Spring JMS 配置文件</description>

</beans>



然后再加入Embedded Broker

<!-- lets create an embedded ActiveMQ Broker -->
<amq:broker useJmx="false" persistent="false">
<amq:persistenceAdapter>
<amq:amqPersistenceAdapter directory="I:/amq"/> //加入这句,就算服务器关闭,信息也不会丢失。
</amq:persistenceAdapter>
<amq:transportConnectors>
<amq:transportConnector uri="vm://localhost:0" />
</amq:transportConnectors>
</amq:broker>


加入连接

<!-- ActiveMQ connectionFactory to use -->
<amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost"/>


队列

<!-- ActiveMQ destinations to use -->
<amq:queue name="destination" physicalName="myqueue"/>


JmsTemplate用来发送接收,还有转换器InnerMessageConverter,转换对象

<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"></property>
<property name="defaultDestination" ref="destination"></property>
<property name="messageConverter" ref="innerMessageConverter"> </property>
</bean>

<bean id="innerMessageConverter" class="jmu.xmpg.service.jms.InnerMessageConverter"></bean>



MDB和监听容器

<bean id="messageListener" class="jmu.xmpg.service.jms.MessageMDB"></bean>

<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer" lazy-init="false">
<property name="connectionFactory" ref="connectionFactory"></property>
<property name="destination" ref="destination"></property>
<property name="messageListener" ref="messageListener"></property>
<property name="concurrentConsumers" value="5"></property>
<!-- 0:CACHE_NONE,1:CACHE_CONNECTION,2:CACHE_SESSION,3:CACHE_CONSUMER,4:CACHE_AUTO -->
<property name="cacheLevel" value="0"/>
</bean>


[b]总结:重点在于头部引入的amq空间,另外就是要加入activemq-all-5.2.0.jar 、spring-jms.jar 和 xbean-spring-3.4.jar,这些包在 apache-activemq-5.2.0\lib\optional 下有。
[/b]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值