JMS开发笔记
1、JMS服务器下载、安装、启动。
2、下载JMS服务器apache-activemq-5.3.2-bin.zip。
3、解压D:\Program Files\apache-activemq-5.3.2
4、启动D:\Program Files\apache-activemq-5.3.2\bin下的activemq.bat
5、访问http://127.0.0.1:8161/admin/来确定JMS服务器是否安装正常。
6、SPRING集成ACTIVEMQ利用JNDI
配置TOMCAT的JNDI。
如下:找到D:\Program Files\jakarta-tomcat-5.5.9\conf下的context.xml配置文件。修改
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<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="TOOL.DEFAULT"/>
</Context>
applicationContext.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
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-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- lets create an embedded ActiveMQ Broker -->
<bean id="jmsConnectionFactory"
value="java:comp/env/jms/ConnectionFactory"/>
</bean>
<bean id="jmsQueue"
value="java:comp/env/jms/Queue"/>
</bean>
<bean id="jmsTemplate"
ref="jmsConnectionFactory"/>
<property name="defaultDestination" ref="jmsQueue"/>
</bean>
<bean id="sender"
ref="jmsTemplate"/>
</bean>
<bean id="receive" ref="jmsConnectionFactory"/>
<property name="destination" ref="jmsQueue"/>
<property name="messageListener" ref="receive"/>
</bean>
</beans>