Spring JMS 整合Tomcat和ActiveMQ
来源:互联网 发布:矩阵的逆 编辑:程序博客网 时间:2024/06/04 17:56
1.Active MQ安装配置
1.1.下载并解压Active MQ
1.2.双击bin/activemq.bat启动Active MQ
1.3.浏览器输入http://localhost:8161/admin/ ,可以图形化界面管理activemq
1.4.点击Queue,新建一个队列名字叫TestQueue1
2.在Eclipse里面配置Tomcat的context.xml,这样Spring就能以JNDI方式访问ActiveMQ了
加入以下代码
3.导入以下Jar包
activemq-all-5.4.1.jar
commons-logging-1.1.1.jar
javax.jms_1.1.1.jar
spring.asm-3.0.0.RELEASE.jar
spring.beans-3.0.0.RELEASE.jar
spring.context-3.0.0.RELEASE.jar
spring.core-3.0.0.RELEASE.jar
spring.expression-3.0.0.RELEASE.jar
spring.jms-3.0.0.RELEASE.jar
spring.transaction-3.0.0.RELEASE.jar
spring.web-3.0.0.RELEASE.jar
4.编写2个类,一个MessageQueueSender发消息,一个MessageQueueReceiver收消息,为了方便测试,我们还写了一个Servlet调用MessageQueueSender,通过JSP来调用Servlet
5.写Spring的配置文件,假设存在这个文件里:jms-activemq.xml
6.启动tomcat测试看效果
6.1.浏览器输入http://localhost:8080/JMSTest/,随便输入消息比如"Hello",点击submit
6.2.可在控制台看到Hello的信息,表明发送和接受者都已经OK
6.3.还可以在ActiveMQ管理台创建一条消息,点击"Send To"
随便打入一点消息
6.4.可在控制台看到接受者能收到此消息
1.1.下载并解压Active MQ
1.2.双击bin/activemq.bat启动Active MQ
1.3.浏览器输入http://localhost:8161/admin/ ,可以图形化界面管理activemq
1.4.点击Queue,新建一个队列名字叫TestQueue1
2.在Eclipse里面配置Tomcat的context.xml,这样Spring就能以JNDI方式访问ActiveMQ了
加入以下代码
- <Resource name="jms/ConnectionFactory"
- auth="Container"
- type="org.apache.activemq.ActiveMQConnectionFactory"
- description="JMS Connection Factory"
- factory="org.apache.activemq.jndi.JNDIReferenceFactory"
- brokerURL="tcp://localhost:61616"
- brokerName="LocalActiveMQBroker" />
- <Resource name="jms/Queue"
- auth="Container"
- type="org.apache.activemq.command.ActiveMQQueue"
- description="my Queue"
- factory="org.apache.activemq.jndi.JNDIReferenceFactory"
- physicalName="TestQueue1" />
3.导入以下Jar包
activemq-all-5.4.1.jar
commons-logging-1.1.1.jar
javax.jms_1.1.1.jar
spring.asm-3.0.0.RELEASE.jar
spring.beans-3.0.0.RELEASE.jar
spring.context-3.0.0.RELEASE.jar
spring.core-3.0.0.RELEASE.jar
spring.expression-3.0.0.RELEASE.jar
spring.jms-3.0.0.RELEASE.jar
spring.transaction-3.0.0.RELEASE.jar
spring.web-3.0.0.RELEASE.jar
4.编写2个类,一个MessageQueueSender发消息,一个MessageQueueReceiver收消息,为了方便测试,我们还写了一个Servlet调用MessageQueueSender,通过JSP来调用Servlet
5.写Spring的配置文件,假设存在这个文件里:jms-activemq.xml
- <beans xmlns="http://www.springframework.org/schema/beans"
- 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-3.0.xsd">
- <!-- Connection factory -->
- <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
- <property name="jndiName" value="java:comp/env/jms/ConnectionFactory"></property>
- </bean>
- <!-- Queue -->
- <bean id="jmsQueue" class="org.springframework.jndi.JndiObjectFactoryBean"
- lazy-init="true">
- <property name="jndiName" value="java:comp/env/jms/Queue"></property>
- </bean>
- <!-- Spring JMS Template -->
- <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
- lazy-init="true">
- <property name="connectionFactory" ref="jmsConnectionFactory"></property>
- <property name="defaultDestination" ref="jmsQueue"></property>
- </bean>
- <!-- Sender -->
- <bean id="jmsSender" class="com.xp.MessageQueueSender"
- lazy-init="true">
- <property name="jmsTemplate" ref="jmsTemplate"></property>
- </bean>
- <!-- Receiver -->
- <bean id="jmsReceiver" class="com.xp.MessageQueueReceiver">
- </bean>
- <!-- Message Listener -->
- <bean id="listenerContainer"
- class="org.springframework.jms.listener.DefaultMessageListenerContainer">
- <property name="connectionFactory" ref="jmsConnectionFactory"></property>
- <property name="destination" ref="jmsQueue"></property>
- <property name="messageListener" ref="jmsReceiver"></property>
- <property name="autoStartup" value="true" />
- </bean>
- </beans>
6.启动tomcat测试看效果
6.1.浏览器输入http://localhost:8080/JMSTest/,随便输入消息比如"Hello",点击submit
6.2.可在控制台看到Hello的信息,表明发送和接受者都已经OK
6.3.还可以在ActiveMQ管理台创建一条消息,点击"Send To"
随便打入一点消息
6.4.可在控制台看到接受者能收到此消息
0 0
- Spring JMS 整合Tomcat和ActiveMQ
- Spring JMS 整合Tomcat和ActiveMQ
- Spring JMS 整合Tomcat和ActiveMQ
- SPRING JMS 整合ACTIVEMQ
- spring整合activeMq 调试JMS
- spring整合activeMq 调试JMS
- JMS-ActiveMq与Spring整合
- Spring ActiveMQ 整合: JMS 事务管理
- 基于Spring+JMS+ActiveMQ+Tomcat
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- JMS学习(4):--Spring和ActiveMQ整合的完整实例
- 深入浅出JMS(四)--Spring和ActiveMQ整合的完整实例
- 百度导航引擎初始化失败问题解决
- MySQL提示Writing to net的解决方法
- Mysql+servlet实现分页
- Oracle基本操作--数据查询
- mysql left join写法
- Spring JMS 整合Tomcat和ActiveMQ
- 愚蠢的傲慢
- Tree Traversals
- 测试Makefile
- APP弱网测试方案
- Java实现LRU缓存
- mysql安装使用
- Spring事务属性详解
- 可复用面向对象软件基础——设计模式(三)之抽象工厂模式