JMS入门小例子+weblogic的安装及在weblogic中配置JMS服务

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JMS入门小例子+weblogic的安装及在weblogic中配置JMS服务JMS是一个由AS提供的Message服务。它能接受消息产生者(MessageProvider)所发出的消息,并把消息转发给消息消费者(MessageConsumer)。以下是接收端和发送端的详细布署步骤,适用于初学者的学习接收端需要的包:commons-logging-1.1.1.jarjettison-1.0.jarjms-1.1.jarlog4j-1.2.15.jarspring.jarspring-asm-3.0.5.RELEASE.jarspring-beans-3.0.5.RELEASE.jarspring-context-3.0.5.RELEASE.jarspring-core-3.0.5.RELEASE.jarspring-expression-3.0.5.RELEASE.jarspring-jms-2.5.6.jarspring-transaction-3.0.5.jarspring-web-3.0.5.RELEASE.jarweblogic.jarxml-apis.jar发送端需要的包:commons-logging-1.1.1.jarjettison-1.0.jarjms-1.1.jarlog4j-1.2.15.jarspring-asm-3.0.5.RELEASE.jarspring-beans-3.0.5.RELEASE.jarspring-context-3.0.5.RELEASE.jarspring-core-3.0.5.RELEASE.jarspring-expression-3.0.5.RELEASE.jarspring-jms-2.5.6.jarspring-jms.jarspring-transaction-3.0.5.jarweblogic.jarxml-apis.jar一、新建一个工程用做接收端本例名为jmsMessageReceive1、在Web.xml文件中添加如下内容:!--加载多个spring配置文件--context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:spring-jms.xml/param-value/context-paramlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenerlistenerlistener-classorg.springframework.web.util.Log4jConfigListener/listener-class/listenercontext-paramparam-namelog4jConfigLocation/param-nameparam-valueclasspath:log4j.properties/param-value/context-paramcontext-paramparam-namelog4jRefreshInterval/param-nameparam-value60000/param-value/context-param2、在src文件夹下新建spring-jms.xml文件,内容如下:?xmlversion=1.0encoding=UTF-8?beansxmlns=:xsi=:aop=:tx=:jaxws=:schemaLocation=://://://://://://cxf.apache.org/jaxws=jkJndiTemplateclass=org.springframework.jndi.JndiTemplatepropertyname=environmentpropspropkey=java.naming.factory.initialweblogic.jndi.WLInitialContextFactory/proppropkey=java.naming.provider.urlt3://localhost:7001/proppropkey=java.naming.security.principalweblogic/proppropkey=java.naming.security.credentialsweblogic/prop/props/property/beanbeanid=jkJndiConnectionFactoryclass=org.springframework.jndi.JndiObjectFactoryBeanpropertyname=jndiTemplateref=jkJndiTemplate/propertypropertyname=jndiNamevalue=JKFC/property/beanbeanid=jkConnectionFactoryclass=org.springframework.jms.connection.CachingConnectionFactorypropertyname=targetConnectionFactoryref=jkJndiConnectionFactory/propertypropertyname=sessionCacheSizevalue=1/property/beanbeanid=destinationResolverclass=org.springframework.jms.support.destination.JndiDestinationResolverpropertyname=jndiTemplateref=jkJndiTemplate/propertypropertyname=cachevalue=true/propertypropertyname=fallbackToDynamicDestinationvalue=false/property/beanbeanid=jkListenerclass=com.ylw.jms.JmsMessageListener/beanbeanid=jkMsgListenerclass=org.springframework.jms.listener.adapter.MessageListenerAdapterconstructor-argref=jkListener/propertyname=defaultListenerMethodvalue=onMessage//beanbeanid=jkJmsContainerclass=org.springframework.jms.listener.DefaultMessageListenerContainerpropertyname=connectionFactoryref=jkConnectionFactory/propertypropertyname=destinationResolverref=destinationResolver/propertypropertyname=concurrentConsumersvalue=1/propertypropertyname=destinationNamevalue=JKTP/propertypropertyname=messageListenerref=jkMsgListener/property/bean/beans3、在src下新建包com.ylw.jms在jms包下新建class文件JmsMessageListener.java,内容如下:packagecom.ylw.jms;importjavax.jms.JMSException;importjavax.jms.Message;importjavax.jms.MessageListener;importjavax.jms.TextMessage;/****项目名称:jmsMessageReceive*类名称:JMSMessageListener*类描述:JMS消息监听*创建人:ylw*创建时间:2012-3-2下午03:47:00*修改人:ylw*修改时间:2012-3-2下午03:47:00*修改备注:*版本:**/publicclassJmsMessageListenerimplementsMessageListener{/*(non-Javadoc)*@seejavax.jms.MessageListener#onMessage(javax.jms.Message)*/publicvoidonMessage(Messagemessage){System.out.println(监听成功...);Stringmsg=;System.out.println(Message:+message.toString());try{msg=((TextMessage)message).getText();}catch(JMSExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}System.out.println(传入的msg内容为:);System.out.println(msg);}}除此之外,还要在src文件夹下新建log4j.properties文件,这里为了避免初学者到处找所以加入内容,如下:#'rootLogger'Neverexpunge!Weneeditwhenerror!log4j.rootLogger=info,stdout,Rlog4j.logger.com.zephyr.validate.dao=info,Rlog4j.logger.com.zephyr.idsrv.services.impl=info,R#log4j.logger.com.zephyr.idsrv.util.ProperiesHelper=info,stdout,R#log4j.logger.com.zephyr.cis.task.SxccbReadCisPkgTask=debug,stdout,Rlog4j.logger.

1 / 53
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功