??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美一级在线视频,亚洲免费观看,亚洲香蕉视频http://www.aygfsteel.com/clant/category/17975.htmlzh-cnWed, 28 Feb 2007 16:21:57 GMTWed, 28 Feb 2007 16:21:57 GMT60JMS消息中间件开源实?/title><link>http://www.aygfsteel.com/clant/articles/85156.html</link><dc:creator>BPM </dc:creator><author>BPM </author><pubDate>Sun, 03 Dec 2006 02:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/clant/articles/85156.html</guid><wfw:comment>http://www.aygfsteel.com/clant/comments/85156.html</wfw:comment><comments>http://www.aygfsteel.com/clant/articles/85156.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/clant/comments/commentRss/85156.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/clant/services/trackbacks/85156.html</trackback:ping><description><![CDATA[ <a >http://www.open-open.com/53.htm</a> <img src ="http://www.aygfsteel.com/clant/aggbug/85156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/clant/" target="_blank">BPM </a> 2006-12-03 10:38 <a href="http://www.aygfsteel.com/clant/articles/85156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JMS框架开源实?/title><link>http://www.aygfsteel.com/clant/articles/85158.html</link><dc:creator>BPM </dc:creator><author>BPM </author><pubDate>Sun, 03 Dec 2006 02:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/clant/articles/85158.html</guid><wfw:comment>http://www.aygfsteel.com/clant/comments/85158.html</wfw:comment><comments>http://www.aygfsteel.com/clant/articles/85158.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/clant/comments/commentRss/85158.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/clant/services/trackbacks/85158.html</trackback:ping><description><![CDATA[ <a >http://www.open-open.com/37.htm</a> <img src ="http://www.aygfsteel.com/clant/aggbug/85158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/clant/" target="_blank">BPM </a> 2006-12-03 10:38 <a href="http://www.aygfsteel.com/clant/articles/85158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Spring JMSL实现异步消息传?/title><link>http://www.aygfsteel.com/clant/articles/85151.html</link><dc:creator>BPM </dc:creator><author>BPM </author><pubDate>Sun, 03 Dec 2006 02:11:00 GMT</pubDate><guid>http://www.aygfsteel.com/clant/articles/85151.html</guid><wfw:comment>http://www.aygfsteel.com/clant/comments/85151.html</wfw:comment><comments>http://www.aygfsteel.com/clant/articles/85151.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/clant/comments/commentRss/85151.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/clant/services/trackbacks/85151.html</trackback:ping><description><![CDATA[      异步q程通信是面向服务架?SOA)一个重要的l成部分Q因Z业里很多pȝ通信Q特别是与外部组l间的通信Q实质上都是异步的?a target="_blank">Java消息服务</a>(JMS)是用于编写用异步消息传递的JEE应用E序的API。传l的使用JMS APIq行消息传递的实现包括多个步骤Q例如JNDI查询队列q接工厂和Queue资源Q在实际发送和接收消息前创Z个JMS会话? <p>   <a target="_blank"><font color="#800080">Spring框架</font></a>则简化了使用JEElg(包括JMS)的Q务。它提供的模板机刉藏了典型的JMS实现的细节,q样开发h员可以集中精力放在处理消息的实际工作中,而不用担心如何去创徏Q访问或清除JMS资源?/p><p>   本文对Spring JMS API作一个概qͼq过一个运行在JBoss MQ服务器上的web例程来介l如何用Spring JMS API来异步处理(发送和接收Q消息。我通过传统JMS实现和Spring JMS实现两者间的比较,来展CZ用Spring JMS处理消息是如何的单和灉|?/p><h3>异步消息传递和面向服务架构</h3><p>  在现实中Q大多数webh都是同步处理的。例如,当用戯d一个网站,首先输入用户名和密码Q然后服务器验证d合法性。如果验证成功,E序允许该用户q入|站。这里,dh在从客户端接收以后被x处理了。信用卡验证是另一个同步处理的例子Q只有服务器证实输入的信用卡h有效的,同时客户在帐户上有够的存款Q客h被允许l操作。但是让我们思考一下在序处理pȝ上的支付l算步骤。一旦系l证实该用户信用卡的信息是准的Qƈ且在帐户上有_的资金,׃必等到所有的支付l节落实、{账完成。支付结可以异步方式进行,q样客户可以l箋q行核查操作?/p><p>   需要比典型同步h耗费更长旉的请求,可以使用异步处理。另一个异步处理的例子是,在本地贷Ƒ֤理程序中Q提交至自动扉KpȝQAUSQ的信用h处理q程。当借方提交h甌后,抉|公司会向AUS发送请求,以获取信用历史记录。由于这个请求要求得到全面而又详细的信用报告,包括借方C和过ȝ帐户Q最q的付款和其他胦务资料,服务器需要耗费较长的时_几小时或着有时甚至是几天)来对q些h作出响应。客LE序Q应用)要与服务器连接ƈ耗费如此长的旉来等待结果,q是毫无意义的。因此通信应该是异步发生的Q也是Q一旦请求被提交Q它p攄在队列中Q同时客L与服务器断开q接。然后AUS服务从指定的队列中选出hq行处理Qƈ处理得到的消息攄在另一个消息队列里。最后,客户端程序从q个队列中选出处理l果Q紧接着处理q个信用历史数据?/p><h3>JMS</h3><p>   如果您用过JMS代码Q您会发现它与JDBC或JCA很像。它所包含的样本代码创建或JMS资源对象回溯Q得每一ơ您需要写一个新cL发送和接收消息Ӟ都具有更好的代码密集性和重复性。以下序列显CZ传统JMS实现所包括的步骤:</p><ol type="1"><li>创徏JNDI初始上下文(contextQ? </li><li>从JNDI上下文获取一个队列连接工厂? </li><li>从队列连接工厂中获取一个Quene? </li><li>创徏一个Session对象? </li><li>创徏一个发送者(senderQ或接收者(receiverQ对象? </li><li>使用步骤5创徏的发送者或接收者对象发送或接收消息? </li><li>处理完消息后Q关闭所有JMS资源?</li></ol>您可以看刎ͼ步骤6是处理消息的唯一地方。其他步骤都只是理与实际业务要求无关的JMS资源Q但是开发h员必ȝ写ƈl护q些额外步骤的代码? <p> </p><h3>Spring JMS</h3><p>   Spring框架提供了一个模板机制来隐藏Java APIs的细节。JEE开发h员可以用JDBCTemplate和JNDITemplatecL分别讉K后台数据库和JEE资源Q数据源Q连接池Q。JMS也不例外。Spring提供JMSTemplatec,因此开发h员不用ؓ一个JMS实现ȝ写样本代码。接下来是在开发JMS应用E序时Spring所h一些的优势?/p><ol type="1"><li>提供JMS抽象APIQ简化了讉K目标Q队列或主题Q和向指定目标发布消息时JMS的用? </li><li>JEE开发h员不需要关心JMS不同版本Q例如JMS 1.0.2与JMS 1.1Q之间的差异? </li><li>开发h员不必专门处理JMS异常Q因为Spring为所有JMS异常提供了一个未l检查的异常Qƈ在JMS代码中重新抛出?</li></ol>一旦您在JMS应用E序中开始用SpringQ您会ƣ赏到它在处理异步消息传递上的简ѝSpring JMS框架提供多种Javac,可以L实现JMS应用。表1列出了这些类的一部分? <p> </p><p>   ?. Spring JMSc?/p><table class="tabel-general" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><th class="left">cd</th><th class="center">?/th><th class="right">功能</th></tr><tr><td class="left">JmsException</td><td class="center">org.springframework.jms</td><td class="right">只要发生一个JMS异常QSpring框架׃抛出异常Q这个类是这些所抛出的异常的基(抽象Q类?/td></tr><tr><td class="left">JmsTemplate, JmsTemplate102</td><td class="center">org.springframework.jms.core</td><td class="right">q些是辅助类Q用于简化JMS的用,处理JMS资源Q如q接工厂Q目标和发送?接收者对象)的创建和释放。JmsTemplate102是JmsTemplate的子c,使用JMS1.0.2规范</td></tr><tr><td class="left">MessageCreator</td><td class="center">org.springframework.jms.core</td><td class="right">q是JmsTemplatecM用的回叫接口Q它为指定的会话创徏JMS消息?/td></tr><tr><td class="left">MessageConverter</td><td class="center">org.springframework.jms.support.converter</td><td class="right">q个接口充当一个抽象,用来在Java对象与JMS消息之间q行转换?/td></tr><tr><td class="left">DestinationResolver</td><td class="center">org.springframework.jms.support.destination</td><td class="right">q是JmsTemplate用来解析目标名的接口。该接口的默认实现是DynamicDestinationResolver和JndiDestinationResolve</td></tr></tbody></table><p>  在接下来的部分,我将详细解释?所列的一部分c(例如JmsTemplateQDestinationResolver和MessageConverterQ?/p><h3>JMSTemplate</h3><p>  JmsTemplate提供了几U辅助方法,用来执行一些基本操作。要开始用JmsTemplate前,您需要知道JMS供应商支持哪个JMS规范Q?a target="_blank">JBoss AS 4.0.2</a>?a target="_blank">WebLogic 8.1</a>服务器支持JMS 1.0.2规范。WebLogic Server 9.0包括了对<a target="_blank">JMS 1.1</a>规范?a target="_blank">支持</a>。JMS 1.1l一了点对点QPTPQ和发布/订阅QPub/SubQ域的编E接口。这U改变的l果是Q开发h员可以创Z个事务会话,然后在这同一个JMS会话里,可以从一个Queue(PTP)中接收消息,同时发送另一个消息到一个Topic(Pub/Sub)。JMS 1.1向后兼容JMS 1.0Q应此根据JMS 1.0~写的代码仍可以适用于JMS 1.1?/p><p>   JmsTemplate提供多种发送和接收消息的方法。表2列出了这些方法的一部分?/p><p>   ?. JMS templateҎ</p><table class="tabel-general" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><th class="left">Ҏ名称</th><th class="right">功能</th></tr><tr><td class="left">send</td><td class="right">发送消息至默认或指定的目标。JmsTemplate包含sendҎQ它通过javax.jms.Destination或JNDI查询来指定目标?/td></tr><tr><td class="left">receive</td><td class="right">从默认或指定的目标接收消息,但只会在指定的时间后传递消息。我们可以通过receiveTimeout属性指定超时时间?/td></tr><tr><td class="left">convertAndSend</td><td class="right">q个Ҏ委托MessageConverter<a target="_blank">接口</a>实例处理转换q程Q然后发送消息至指定的目标?/td></tr><tr><td class="left">receiveAndConvert</td><td class="right">从默认或指定的目标接收消息。ƈ消息{换ؓJava对象?/td></tr></tbody></table><p>  目标可以通过JNDI上下文保存和获取。当配置SpringE序上下文(application contextQ时Q我们可以用JndiObjectFactoryBeancd得对JMS的引用。DestinationResolver接口是用来把目标名称解析成JMS目标Q当应用E序存在大量目标Ӟq是非常有用的。DynamicDestinationResolver(DestinationResolver的默认实?是用来解析动态目标的?/p><p>   MessageConverter接口定义了将<a target="_blank">Java对象</a>转换为JMS消息的约定。通过q个转换器,应用E序代码可以集中于处理事务对象,而不用ؓ对象如何表示为JMS消息q样的内部细节所困饶。SimpleMessageConverter(和SimpleMessageConverter102)是MessageConverter的默认实现。可使用它们分别String转换为JMS TextMessageQ字节数l?byte[])转换为JMS BytesMessageQMap转换为JMS MapMessageQ和Serializable对象转换为JMS ObjectMessage。您也可以编写自定义的MessageConverter实例Q通过XMLl定框架Q例?a target="_blank">JAXB</a>Q?<a target="_blank">Castor</a>Q?a target="_blank">Commons Digester</a>Q?a target="_blank">XMLBeans</a>?a target="_blank">XStream</a>Q,来实现XML文档到TextMessage对象的{换?/p><h3>CZE序</h3><p>  我将用一个贷Ƅ请处理系l(命名为LoanProcQ示例来演示如何在JMS应用E序中用Spring。作ƄL一部分QLoanProc通过发送贷ƾ详情(hIDQ借方名字Q借方的SSNQ贷ƾ期限和h数额Q,从AUSpȝ获得信用历史详情。ؓ了简便v见,我们Z两个基本参数来表CZ用历史详情:信用分数Q又名FICO得分Q和h数额。让我们假设处理信用查请求是按以下业务规则进行的Q?/p><ol type="1"><li>如果h数额{于或低?000Q借方必须臛_有一??的信用(也就是,借方的FICO得分?80?99之间Q? </li><li>如果h数额高于,000Q借方必须臛_?很好"的信用,意味着借方的信用得分要高于700?</li></ol><h3>h甌使用案例</h3><p>  信用h处理使用案例包括以下几个步骤Q?/p><ol type="1"><li>用户在贷Ƅ请页面输入贷ƾ详情ƈ提交h甌? </li><li>发送请求到一个名为CreditRequestSendQueue的消息队列。然后程序发送贷ƾ详情到AUSpȝQ获取信用历史详情? </li><li>AUSpȝ从队列中挑出h详情Qƈ使用h参数从它的数据库中获取信用历史信息? </li><li>然后AUS找到的借方的信用历史信息创Z个新的消息,发送到一个新的名为CreditRequestReceiveQueue的消息队列? </li><li>最后,LoanProc从接攉列中选出响应消息Q处理贷Ƅh军_是否批准或否决申诗?</li></ol><p>  在这个例E中Q两个消息队列都配置在同一个JBoss MQ server上。用案例用?的序列图QSequenceDiagramQ表C?/p><p align="center"><a target="_blank"><img height="169" alt="序列? src="http://dev2dev.bea.com.cn/images/image060511001.gif" width="300" border="0" /></a><br /><br />?.h处理E序的序列图 (单击截图来查看完整视?</p><p>   下面的表3昄了在例程中我所使用的不同技术和<u><a target="_blank">开?/a></u>框架Qƈ按应用逻辑层排列?/p><p>   ?. 在JMS应用E序中用的框架</p><table class="tabel-general" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><th class="left">逻辑?/th><th class="right">技?框架</th></tr><tr><td class="left">MVC</td><td class="right">Spring MVC</td></tr><tr><td class="left">Service</td><td class="right">Spring Framework (version 2.1)</td></tr><tr><td class="left">JMS API</td><td class="right">Spring JMS</td></tr><tr><td class="left">JMS Provider</td><td class="right"><a target="_blank">JBoss</a> MQ (version 4.0.2)</td></tr><tr><td class="left">JMS Console</td><td class="right">Hermes</td></tr><tr><td class="left">IDE</td><td class="right">Eclipse 3.1</td></tr></tbody></table><h3>使用Hermes讄JMS资源</h3><p>  Z异步处理消息Q首先我们需要消息队列发送和接收消息。我们可以用Jboss里的配置<a target="_blank">XML文g</a>创徏一个新的消息队列,然后使用JMS控制台浏览队列的详细情况。清?昄了配|JMS的XML配置代码片断Q这个应该加入到jbossmq-destinations-service.xml文gQ位?JBOSS_HOME%server lldeploy-hasingletonjm文g夹下。)</p><p>   清单1.JBoss MQ Server上JMS队列的配|?/p><pre class="code"><!-- Credit Request Send Queue --> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=CreditRequestSendQueue"> <depends optional-attribute-name="DestinationManager"> jboss.mq:service=DestinationManager </depends> </mbean> <!-- Credit Request Receive Queue --> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=CreditRequestReceiveQueue"> <depends optional-attribute-name="DestinationManager"> jboss.mq:service=DestinationManager </depends> </mbean> </pre><p>  现在Q让我们看看如何使用一个名为Hermes的JMS工具来浏览消息队列?a target="_blank">Hermes</a>是一个Java Swing应用E序Q它可以创徏、管理和监视JMS提供商(例如<a target="_blank">JBossMQ</a>Q?a target="_blank">WebSphereMQ</a>Q?a target="_blank">ActiveMQ</a>?a target="_blank">Arjuna</a>服务器)里的JMS目标。从它的<a target="_blank">|站</a>上下载HermesQ解压羃.zip文g到本地目录(例如Qc:dev oolshermesQ。一旦安装完成,双击文ghermes.batQ位于bin文g夹下Q启动程序?/p><p>   要在Hermes里配|JBossMQ服务器,请参考Hermes|站上的q个<a target="_blank">演示</a>。它有着的step-by-step可视化指C来配置JBoss MQ。当配置一个新的JNDI初始上下文时Q请输入下面的信息?/p><ul type="disc"><li>providerURL = jnp://localhost:1099 </li><li>initialContextFactory = org.jnp.interfaces.NamingContextFactory </li><li>urlPkgPrefixes = org.jnp.interfaces:org.jboss.naming </li><li>securityCredentials = admin </li><li>securityPrincipal = admin </li></ul><p>  当您创徏新的目标Ӟ误入queue/CreditRequestSendQueue和queue/CreditRequestReceiveQueue。图2昄了JMS控制台的ȝ口,其中有ؓJMS例程创徏的新的消息队列?/p><p align="center"><a target="_blank"><img height="159" alt="Hermes中所有目标的截图" src="http://dev2dev.bea.com.cn/images/image060511003.jpg" width="312" border="0" /></a><br /><br />?2. Hermes中所有目标的截图.Q单L图来查看完整视图Q?/p><p>   下面的图3昄了在从消息发送者类发送消息到CreditRequestSendQueue后,Hermes JMS控制台及消息队列的截图。您可以看见?个消息在队列中,控制台显CZ消息详情Q例如消息IDQ消息目标,旉戛_实际的消息内宏V?/p><p align="center"><a target="_blank"><img height="159" alt="Hermes中所有队列的截图" src="http://dev2dev.bea.com.cn/images/image060511005.jpg" width="312" border="0" /></a><br /><br />?3. Hermes中所有队列的截图.Q单L图来查看完整视图Q?/p><p>   在例E中使用的队列名U和其他JMS和JNDI参数见表 4?/p><p>   ?. Spring JMS配置参数</p><table class="tabel-general" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><th class="left">参数名称</th><th class="right">参数?/th></tr><tr><td class="left">Initial Context Factory</td><td class="right">org.jnp.interfaces.NamingContextFactory</td></tr><tr><td class="left">Provider URL</td><td class="right">localhost:8080</td></tr><tr><td class="left">Initial Context Factory URL Packages</td><td class="right">org.jnp.interfaces:org.jboss.naming</td></tr><tr><td class="left">Queue Connection Factory</td><td class="right">UIL2ConnectionFactory</td></tr><tr><td class="left">Queue Name</td><td class="right">queue/CreditRequestSendQueue, queue/CreditRequestReceiveQueue</td></tr></tbody></table><h3>Spring配置</h3><p>  既然我们已经有了q行例程所需要的JMS目标Q现在该了解?a target="_blank">XML</a> Spring配置文gQ名为spring-jms.xmlQ来l配JMSlg的具体细节了。这些组件是ҎInversion of Controller (IOC)<a target="_blank">设计模式</a>里的讄方式注入原则Qsetter injection principleQ,用JMS对象实例cȝ配的。让我们详细查看q些lgQƈ为每一个JMSlg演示一DXML配置代码?/p><p>   JNDI上下文是取得JMS资源的v始位|,因此首先我们要配|JNDI模板。清?昄了名为jndiTemplate的Spring beanQ其中列有JNDI初始上下文所必需的常用参数?/p><p>   清单2. JNDI上下文模?/p><pre class="code"><bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"> <property name="environment"> <props> <prop key="java.naming.factory.initial"> org.jnp.interfaces.NamingContextFactory </prop> <prop key="java.naming.provider.url"> localhost </prop> <prop key="java.naming.factory.url.pkgs"> org.jnp.interfaces:org.jboss.naming </prop> </props> </property> </bean> </pre><p>  接着Q我们配|队列连接工厂。清?昄了队列连接工厂的配置?/p><p>   清单3. JMS队列q接工厂配置</p><pre class="code"><bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiTemplate"> <ref bean="jndiTemplate"/> </property> <property name="jndiName"> <value>UIL2ConnectionFactory</value> </property> </bean> </pre><p>  我们定义2个JMS目标来发送和接收消息。详情见清单4??/p><p>   清单4. 发送队列配|?/p><pre class="code"><bean id="sendDestination" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiTemplate"> <ref bean="jndiTemplate"/> </property> <property name="jndiName"> <value>queue/CreditRequestSendQueue</value> </property> </bean> </pre><p>  清单5. 接收队列配置</p><pre class="code"><bean id="receiveDestination" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiTemplate"> <ref bean="jndiTemplate"/> </property> <property name="jndiName"> <value>queue/CreditReqeustReceiveQueue</value> </property> </bean> </pre><p>  然后我们再来配置JmsTemplatelg。在例程中我们用JmsTemplate102。同时用defaultDestination属性来指定JMS目标?/p><p>   清单6. JMS模板配置</p><pre class="code"><bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate102"> <property name="connectionFactory"> <ref bean="jmsQueueConnectionFactory"/> </property> <property name="defaultDestination"> <ref bean="destination"/> </property> <property name="receiveTimeout"> <value>30000</value> </property> </bean> </pre><p>  最后我们配|发送者和接收者组件。清??分别是Sender ?Receiver对象的配|?/p><p>   清单7. JMS Sender配置</p><pre class="code"><bean id="jmsSender" class="springexample.client.JMSSender"> <property name="jmsTemplate"> <ref bean="jmsTemplate"/> </property> </bean> </pre><p>  清单8. JMS Receiver配置</p><pre class="code"><bean id="jmsReceiver" class="springexample.client.JMSReceiver"> <property name="jmsTemplate"> <ref bean="jmsTemplate"/> </property> </bean> </pre><h3>试及监?/h3><p>  我写了一个测试类Q命名ؓLoanApplicationControllerTestQ用来测试LoanProcE序。我们可以用这个类来设定贷Ƒ֏C及调用信用请求服务类?/p><p>   让我们看一下不使用Spring JMS API而用传lJMS开发途径的消息发送者实例。清?昄了MessageSenderJMSc里的sendMessageҎQ其中包含了使用JMS API处理消息的所有必需步骤?/p><p>   清单9. 传统JMS实例</p><pre class="code">public void sendMessage() { queueName = "queue/CreditRequestSendQueue"; System.out.println("Queue name is " + queueName); /* * Create JNDI Initial Context */ try { Hashtable env = new Hashtable(); env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); env.put("java.naming.provider.url","localhost"); env.put("java.naming.factory.url.pkgs", "org.jnp.interfaces:org.jboss.naming"); jndiContext = new InitialContext(env); } catch (NamingException e) { System.out.println("Could not create JNDI API " + "context: " + e.toString()); } /* * Get queue connection factory and queue objects from JNDI context. */ try { queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("UIL2ConnectionFactory"); queue = (Queue) jndiContext.lookup(queueName); } catch (NamingException e) { System.out.println("JNDI API lookup failed: " + e.toString()); } /* * Create connection, session, sender objects. * Send the message. * Cleanup JMS connection. */ try { queueConnection = queueConnectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender(queue); message = queueSession.createTextMessage(); message.setText("This is a sample JMS message."); System.out.println("Sending message: " + message.getText()); queueSender.send(message); } catch (JMSException e) { System.out.println("Exception occurred: " + e.toString()); } finally { if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) {} } } } </pre><p>  现在Q我们来看看使用了Spring的消息发送者实例。清?0昄了MessageSenderSpringJMScMsendҎ的代码?/p><p>   清单10. 使用Spring API的JMS实例</p><pre class="code">public void send() { try { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "spring-jms.xml"}); System.out.println("Classpath loaded"); JMSSender jmsSender = (JMSSender)appContext.getBean("jmsSender"); jmsSender.sendMesage(); System.out.println("Message sent using Spring JMS."); } catch(Exception e) { e.printStackTrace(); } } </pre><p>  如您所见,通过使用配置文gQ所有与理JMS资源有关的步骤都交由Spring容器处理。我们只需引用一个JMSSender对象Q然后调用对象里的sendMessageҎ?/p><h3>l束?/h3><p>  在本文中Q我们看到Spring框架是如何用JMS API化异步消息传递。SpringL了所有用JMS处理消息所必需的样本代码(例如得到一个队列连接工厂,从Java代码里创建队列和会话对象Q在q行时用配|文件对它们q行l配Q。我们可以动态的交换JMS资源对象Q而不必修改Q何Java代码Q这要感谢Inversion of Control (IOC) 原则的力量?/p><p>  既然异步消息传递是SOA框架的整体构成部分,Spring很适合U_到SOA工具集。此外,JMS理工具Q如HermesQ得创建、管理和监督JMS资源变得ҎQ特别是对于pȝ理员来说?/p><h3>参考资?/h3><ul type="disc"><li>本文配套?a target="_blank">CZ代码</a></li><li><a target="_blank">Spring JMS documentation</a></li><li>"<a target="_blank">1-2-3 Messaging with Spring JMS</a>" </li><li><a target="_blank">JBoss MQ wiki</a></li></ul><p><strong>原文出处:</strong><a target="_blank">http://www.onjava.com/pub/a/onjava/2006/02/22/asynchronous-messaging-with-spring-jms.html</a></p><img src ="http://www.aygfsteel.com/clant/aggbug/85151.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/clant/" target="_blank">BPM </a> 2006-12-03 10:11 <a href="http://www.aygfsteel.com/clant/articles/85151.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ǿ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ӳ</a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank">˾</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ž</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ԭ</a>| <a href="http://" target="_blank">ϻ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ָɽ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>