首页 > 代码库 > 项目从weblogic转移到tomcat时JMS服务的更换
项目从weblogic转移到tomcat时JMS服务的更换
在tomcat服务器中配置jms
项目原本使用的是weblogic的JMS服务和Spring的JMSTemplate ,这样配置可以不修改项目中消息操作的代码
一、下载activemq 解压后启动,访问http://localhost:8161/admin
默认账户密码 admin:admin,点击Queue,新建一个队列TestQueue1
二、在tomcat/webapp/META-INF下添加context.xml
分别配置数据源,activemq连接工厂,队列,导入activemq-all.jar
<Resource name="jdbc/oracleDB" auth="Container" type="javax.sql.DataSource" password="xx " username="xx" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.0.0:1521:xx" maxIdle="2" maxWait="5000" maxActive="4" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" />
<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" />
|
三、在springbeans-jms.xml文件中配置以下信息:
<!-- Connection factory --> <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="http://www.mamicode.com/java:comp/env/jms/ConnectionFactory"></property> </bean>
<!-- Queue --> <bean id="jmsQueue" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true"> <property name="jndiName" value="http://www.mamicode.com/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>
<bean id="jmsProducer" class="com.jyd.ebank.util.JmsProducer"> <property name="jmsTemplate" ref="jmsTemplate"/> </bean>
<bean id="messageListener" class="com.jyd.ebank.util.JmsListener" />
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="concurrentConsumers" value="http://www.mamicode.com/5" /> <property name="connectionFactory" ref="jmsConnectionFactory" /> <property name="destination" ref="jmsQueue" /> <property name="messageListener" ref="messageListener" /> <property name="sessionAcknowledgeModeName" value="http://www.mamicode.com/AUTO_ACKNOWLEDGE"/> </bean> |