转载请出自出处:http://eksliang.iteye.com/blog/2242743
在上篇文章中ActiveMQ与Spring集成在spring中我们使用ActiveMQ自带的连接工厂创建connectionFactory,在这篇文章将介绍在spring中使用ActiveMQ自己的命名空间来声明连接工厂,目的地等等!
使用Active自己的命名空间工厂,需要导入一个jar包,mave地址如下:
<dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> <version>3.7</version> </dependency>
此时Spring配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.2.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd"> <!-- 使用activeMQ自己的Spring配置命名空间来声明 连接地址--> <amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616"/> <!-- 声明队列地址 --> <amq:queue id="queue" physicalName="queue.destination"></amq:queue> <!-- 声明主题地址 --> <amq:topic id="topic" physicalName="topic.destination"></amq:topic> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="connectionFactory"/> <property name="defaultDestination" ref="queue"></property> </bean> <!-- 装配发送消息实体 --> <bean id="queueSendService" class="com.gosun.jms.QueueSendService"> <property name="jmsTemplate" ref="jmsTemplate"/> </bean> <!-- 装配接收消息实体 --> <bean id="queuesAcceptService" class="com.gosun.jms.QueuesAcceptService"> <property name="jmsTemplate" ref="jmsTemplate"/> </bean> </beans>
测试代码跟上篇文章一样
public static void main(String[] args) { ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext-activeMQ1.xml"); //先发送消息 QueueSendService qss = (QueueSendService) context.getBean("queueSendService"); User user = new User(); user.setUserName("ickes"); user.setUserPwd("123456"); user.setSal(12000F); qss.send(user); //接收消息 QueuesAcceptService qas = (QueuesAcceptService) context.getBean("queuesAcceptService"); qas.receive(); }
使用ActiveMQ只带的命名空间进行声明,会发现配置会少很多,代码也更加简洁!
相关推荐
ActiveMQ与Spring线程池整合的一个实例。 lib库没有上传。 对于实例的讲解,在竹子的论坛有我对这个实例的帖子(http://www.java2000.net/viewthread.jsp?tid=1167) lib中包含: apache-activemq-4.1.1.jar ...
内容包含activeMQ的服务器,activeMQ客户端已和Spring集成好
Spring集成ActiveMQ配置
NULL 博文链接:https://firezhfox.iteye.com/blog/1753688
NULL 博文链接:https://firezhfox.iteye.com/blog/1755004
NULL 博文链接:https://bijian1013.iteye.com/blog/2311358
NULL 博文链接:https://firezhfox.iteye.com/blog/1753847
ActiveMQ spring 配置方案详解。
spring集成activemq例子demo
spring集成ActiveMQ的配置过程
Spring集成ActiveMQ配置
activemq消息队列集成 到springMVC所需集成jar包。。。。。。。。。。。。。。。。。。。。。
Spring boot 和内置ActiveMQ集成例子,通过代码学习Spring boot 和内置ActiveMQ集成。
spring集成activeMQ框架 配置方式(内含三种常见的消息接受监听方式的配置)JMS 配置测试等等
spring boot 集成activemq Datajpa Ehcache 里面有详细的例子
ActiveMQ通过与Spring集成后,消息队列,消息监听都可以很灵活的配置
此项目比较完整的演示了ActiveMQ与Spring整合的相关示例,由于机器限制暂时做的是单项目自测,如有需要可以自己完善。