主要的代码实现在上一篇文章,而本篇文章重点是说明 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>
总结:重点在于头部引入的amq空间,另外就是要加入activemq-all-5.2.0.jar 、spring-jms.jar 和 xbean-spring-3.4.jar,这些包在 apache-activemq-5.2.0\lib\optional 下有。
分享到:
相关推荐
基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示: •Spring 2.5 •ActiveMQ 5.4.0 •Tomcat 6.0.30 下面通过学习与配置,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...
springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot...
基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示:Spring 3.2.0,ActiveMQ 5.4.3,Tomcat 6.0.43。本例通过详细的说明和注释,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
spring+activemq必备jar包:activeio-core-3.1.4.jar,activemq-all-5.13.2.jar,activemq-pool-5.13.2.jar,commons-pool2-2.4.2.jar
NULL 博文链接:https://zw7534313.iteye.com/blog/478392
rt ActiveMQ5.1+Spring2.5的Demo
【毕业设计】基于springCloud +activemq的智慧物业综合管理平台【后端源码】.zip 技术架构: Java + spring cloud + mybatis + mysql + activemq + redis 1.0 小区商家 1 美食 外卖 生鲜 超市 家政 其他 2.0 小区...
spring3.0整合了activemQ和jms可以发送信息和接收消息
Spring+ActiveMQ整合实例代码工程,朋友提供给我参考的,我备个份以便下次查阅,也分享给大家,看看对大家有没有帮助了
spring+activemq,示例工程,演示JMS消息通信。。。。。。。
NULL 博文链接:https://ihenu.iteye.com/blog/2270078
Spring MVC + JPA + MQ + redis +activemq 集成项目实例 详细描述,集成环境搭建
整合spring3 blazeds activeMQ(jms) 通过flex consumer来订阅消息。时时更新消息内容
基于Springboot+ActiveMQ事务==本地事件表+activemq,即利用activemq+本地事件表实现分布式事务的功能
基于Spring+JMS+ActiveMQ+Tomcat,做一个Spring4.1.0和ActiveMQ5.11.1整合实例,实现了Point-To-Point的异步队列消息和PUB/SUB(发布/订阅)模型,简单实例,不包含任何业务。
Spring+JMS+ActiveMQ+Tomcat jar下载,在博客主页有实例,欢迎换看
学习用Java写一个聊天室,spring4.2.5+mybatis+mysql+shiro+activemq+html5
基于Maven的Spring+ActiveMQ,比较贴合实际生产,只实现了Topic,queue改点配置就行了
spring+springmvc+mybatis+mongodb+ActiveMQ+CXF