??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品另类一区,麻豆导航在线观看,日本一区二区三区免费看http://www.aygfsteel.com/caojianhua/category/46514.html你必L认,我们生存的这个世界取决于自n的能力而非别h的保?AW)zh-cnThu, 26 Jul 2012 16:27:12 GMTThu, 26 Jul 2012 16:27:12 GMT60JMS规范及相兛_?/title><link>http://www.aygfsteel.com/caojianhua/archive/2012/07/26/384095.html</link><dc:creator>初一七月</dc:creator><author>初一七月</author><pubDate>Thu, 26 Jul 2012 09:41:00 GMT</pubDate><guid>http://www.aygfsteel.com/caojianhua/archive/2012/07/26/384095.html</guid><wfw:comment>http://www.aygfsteel.com/caojianhua/comments/384095.html</wfw:comment><comments>http://www.aygfsteel.com/caojianhua/archive/2012/07/26/384095.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/caojianhua/comments/commentRss/384095.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/caojianhua/services/trackbacks/384095.html</trackback:ping><description><![CDATA[JMS是一U应用于异步消息传递的标准APIQ作为Javaq_的一部分QJMS可以允许不同应用、不同模块之间实现可靠、异步数据通信?br /><br /><strong>一些概?/strong><br /><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><br />JMS provider<br />    An implementation of the JMS interface for a Message Oriented Middleware (MOM). Providers are implemented as either a Java JMS implementation or an adapter to a non-Java MOM.<br />JMS client<br />    An application or process that produces and/or receives messages.<br />JMS producer/publisher<br />    A JMS client that creates and sends messages.<br />JMS consumer/subscriber<br />    A JMS client that receives messages.<br />JMS message<br />    An object that contains the data being transferred between JMS clients.<br />JMS queue<br />    A staging area that contains messages that have been sent and are waiting to be read. Note that, contrary to what the name queue suggests, messages don't have to be delivered in the order sent. A JMS queue only guarantees that each message is processed only once.<br />JMS topic<br />    A distribution mechanism for publishing messages that are delivered to multiple subscribers. </div><br />在JMS中,支持两种消息模型Q点对点QPoint-to-pointQ和发布-订阅(Publish and subscribe)Q这两种模式分别对应于JMS中的两种消息目标QMessage DestinationQ?队列及主题?br /><br />在点对点模型中,每个消息都有一个发送者和一个接收者,消息中介QbrokerQ收到发送者的消息Q会(x)消息放入队列中Q而接收者请求ƈ接收队列中的一条消息后Q这条消息就?x)从队列中删除。消息队列中的每条消息只能投递给一个接收者,但ƈ不意味着只能使用一个接收者从队列中取消息Q根据业务需要,可以使用多个接收者同时从队列中请求消息,分担处理压力。但是需要注意的是,单个接收者收到的消息是按照发送顺序的Q多个接收者因为多U程的关p,q不能保证收到的消息一定是原序的?br /><br />在发?订阅模式中,消息?x)发送给一个主题,但是与点对点模式不同的是消息不再只被投递给一个接收者,而是所有此主题的订阅者都?x)收到该消息?br /><br /><strong>JMS消息cd<br /><br /></strong>在JMS1.1规范中,定义了五U消息类型,分别为:(x)<br />1.StreamMessage Q消息体?Java ,写入和读出都是顺序的<br />2.MapMessage Q消息体包含 key-value 对, key ?String Q?value 为基本类型,可以通过q代器访?br />3.TextMessage Q消息体?String<br />4.ObjectMessage Q消息体是可序列化的 Java 对象<br />5.BytesMessage Q消息体是字节数l?br /><div>可以通过 message.clearBody() 来清除消息体Q但在消费端Q消息体是只ȝQ针Ҏ(gu)息的写操作都?x)抛?MessageNotWritableException 异常</div><br /><strong>JMS消息?/strong><br /><div>所有消息的消息头都具体相同的字D,用于 JMS Client 以及 JMS Provider 对它们进行区别以及进行消息\?/div>1.JMSDestination<br /><div>消息发送的目的圎ͼ队列或主题)Q创建消息时可以讄 JMSDestination Q但是在发送完成时其g(x)更新为发送方所指定?JMSDestination Q也是说发送前该字D会(x)被忽略;当消息被消费Ӟ该字D늚g在它被发送时被设|的值是相同?/div>以下所有示例均ZActiveMQ<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Session session = connection.createSession(<span style="color: #0000FF; ">false</span>, Session.AUTO_ACKNOWLEDGE);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏2个目的地</span><span style="color: #008000; "><br /></span>Destination destination = session.createQueue("JMS.DEMO");<br />Destination destination2 = session.createQueue("JMS.DEMO2");<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏生?/span><span style="color: #008000; "><br /></span>MessageProducer publisher = session.createProducer(destination);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄传输模式</span><span style="color: #008000; "><br /></span>publisher.setDeliveryMode(DeliveryMode.PERSISTENT);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏消息</span><span style="color: #008000; "><br /></span>TextMessage message = session.createTextMessage("Test Message");<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄消息的目的地为destination2</span><span style="color: #008000; "><br /></span>message.setJMSDestination(destination2);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 发送消?/span><span style="color: #008000; "><br /></span>publisher.send(message);<br /><br />System.out.println(message.getJMSDestination());</div><br /><div>代码中,通过 message.setJMSDestination(destination2); 讄?message ?JMSDestination 消息头属性|我们再看看其输出l果<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->queue:<span style="color: #008000; ">//</span><span style="color: #008000; ">JMS.DEMO</span></div><br /><div>通过q个例子可以看出Q虽然在发送前讄了消息的目的圎ͼ但是发送后消息的目的地被重|了</div>2.JMSDeliveryMode<br /><div>指明消息的传输模式,有两U:(x)</div><div>DeliveryMode.PERSISTENT Q保证消息仅传一ơ, JMS Provider 服务停止后消息不?x)丢失?/div><div>DeliveryMode.NON_PERSISTENT Q消息最多传一ơ,消息?x)?JMS Provider 停止后丢失;</div><div>?JMSDestination 一P在发送前讄的会(x)被忽?/div><br />看下面的例子<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Session session = connection.createSession(<span style="color: #0000FF; ">false</span>, Session.AUTO_ACKNOWLEDGE);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏目的?/span><span style="color: #008000; "><br /></span>Destination destination = session.createQueue("JMS.DEMO");<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏生?/span><span style="color: #008000; "><br /></span>MessageProducer publisher = session.createProducer(destination);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄传输模式</span><span style="color: #008000; "><br /></span>publisher.setDeliveryMode(DeliveryMode.PERSISTENT);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 发送PERSISTENT消息</span><span style="color: #008000; "><br /></span>publisher.send(session.createTextMessage("PERSISTENT MESSAGE"));<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄传输模式</span><span style="color: #008000; "><br /></span>publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 发送PERSISTENT消息</span><span style="color: #008000; "><br /></span>publisher.send(session.createTextMessage("NON_PERSISTENT MESSAGE"));</div><br /><div>例子中分别发送了一?PERSISTENT 的消息和一?NON_PERSISTENT 的消息;?Active MQ 重启后,启动消费端,收到的消息如?br /><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->PERSISTENT MESSAGE</div></div></div><br /><div>该例子说明,?JMS Provider 重启后, NON_PERSISTENT 消息丢失了,?PERSISTENT 消息能正常被消费者消?/div>3.JMSMessageID<br /><div>?JMS Provider 指定的消息的唯一标识W;同上面的字段一P在发送前讄的会(x)被忽略,在发送完成时Q由 JMS Provider 重置该字D?br /><br />4.JMSReplyTo</div><div>发送端在发送消息时Q可以指定该属性(Z?JMSDestination Q,表示期望收到客户端的响应Q是否响应由消费端决?/div><div></div><div>如下面的例子Q?/div><div>发送端Q?nbsp;</div><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Session session = connection.createSession(<span style="color: #0000FF; ">false</span>, Session.AUTO_ACKNOWLEDGE);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏目的?/span><span style="color: #008000; "><br /></span>Destination destination = session.createQueue("JMS.DEMO");<br />Destination destination2 = session.createQueue("JMS.DEMO3");<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏生?/span><span style="color: #008000; "><br /></span>MessageProducer publisher = session.createProducer(destination);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄传输模式</span><span style="color: #008000; "><br /></span>publisher.setDeliveryMode(DeliveryMode.PERSISTENT);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏消息</span><span style="color: #008000; "><br /></span>TextMessage message = session.createTextMessage("Test Message");<br />message.setJMSReplyTo(destination2);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 发送消?/span><span style="color: #008000; "><br /></span>publisher.send(message);</div><br /><div>接收端(可以Ҏ(gu)情况军_是否需要回复)<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> onMessage(Message message) {<br />    <span style="color: #0000FF; ">try</span> {<br />        System.out.println("Receive message: " + message);<br />        <span style="color: #0000FF; ">if</span> (message.getJMSReplyTo() != <span style="color: #0000FF; ">null</span>) {<br />            session.createProducer(message.getJMSReplyTo()).send(session.createTextMessage("This is a reply to"<br />                                                                                           + message.getJMSReplyTo()));<br />        }<br />    } <span style="color: #0000FF; ">catch</span> (Exception e) {<br />        e.printStackTrace();<br />    }<br />}</div><br />5.JMSRedelivered<br /><div>当消费者收到带?JMSRedelivered 的消息头Ӟ表明该消息在q去传输q但没有被确?/div><div>JMS Provider 必须对该字段q行讄Q当?true 时即告知消费者该消息是重传的Q消费者需要自行处理重复的消息</div><br />6.JMSExpiration<br /><div>消息的过期时_(d)其gؓ(f)当前旉加上存活旉Q毫U)Q当存活旉讄?0 Ӟ该字D늚g被设|ؓ(f) 0 Q表C永不过期;</div><div>消费端在一般情况下都不?x)接收到q期的消息,?JMS Provider q不保证q一点;</div><div></div><div>下面的例子说明了如何讄消息的过期时?/div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Session session = connection.createSession(<span style="color: #0000FF; ">false</span>, Session.AUTO_ACKNOWLEDGE);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏目的?/span><span style="color: #008000; "><br /></span>Destination destination = session.createQueue("JMS.DEMO");<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏生?/span><span style="color: #008000; "><br /></span>MessageProducer publisher = session.createProducer(destination);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄传输模式</span><span style="color: #008000; "><br /></span>publisher.setDeliveryMode(DeliveryMode.PERSISTENT);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏消息</span><span style="color: #008000; "><br /></span>TextMessage message = session.createTextMessage("Test Message");<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 发送消?/span><span style="color: #008000; "><br /></span>publisher.setTimeToLive(5000);<br />publisher.send(message);</div><br />7.JMSPriority<br /><div>消息的优先Q?0 代表最低优先Q?9 代表最高优先Q一?0~4 为普通优先Q?5~9 为加快优先</div><div>JMS 规范里ƈ没有要求 JMS Provider 严格按这个优先来实玎ͼ但是可能实现加快优先消息的传输在普通消息的前面</div><div>?JMSDestination 一P该字D在发送前被忽略,在发送完成时重置</div><br /><br /><strong>消息属?/strong><br /><br /><div>除了前面提到的消息头以外Q?JMS 消息q提供了?#8220;属性值对”的支持,以对消息头进行扩展;消息属性主要用于消息选择?(message selector 详见下文 ) </div><br />1.属性名<br /><span style="font-size: small;">属性名必须服务消息选择器的命名规则</span><br /><br />2.属性?br /><div>可以是基本类型及其对象类型以?Map ?List ?String</div><br /><div>下面的例子中Q消息带 HashMap 的属?/div><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Session session = connection.createSession(<span style="color: #0000FF; ">false</span>, Session.AUTO_ACKNOWLEDGE);<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏目的?/span><span style="color: #008000; "><br /></span>Destination destination = session.createQueue("JMS.DEMO");<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏生?/span><span style="color: #008000; "><br /></span>MessageProducer publisher = session.createProducer(destination);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 讄传输模式</span><span style="color: #008000; "><br /></span>publisher.setDeliveryMode(DeliveryMode.PERSISTENT);<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 创徏消息</span><span style="color: #008000; "><br /></span>TextMessage message = session.createTextMessage("Test Message");<br /><span style="color: #008000; ">//</span><span style="color: #008000; "> 发送消?/span><span style="color: #008000; "><br /></span>message.setObjectProperty("myProp", <span style="color: #0000FF; ">new</span> HashMap() {<br /><br />    {<br />        <span style="color: #0000FF; ">this</span>.put("key1", "value1");<br />        <span style="color: #0000FF; ">this</span>.put("key2", "value2");<br />    }<br />});<br />publisher.send(message);</div><br />3.清除属?br /><div>JMS 不能清除单个属性,但可以通过 Message.clearProperties() Ҏ(gu)清除所有消息属?/div><br /><strong>JMS实现QProvider implementationsQ?/strong><br /><br />要用JMSQ必要有相应的实现来管理session以及队列Q从Java EE1.4开始,所有的Java EE应用服务器必d含一个JMS实现?/div>以下是一些JMS实现Q?br /><div>    Apache ActiveMQ</div><div>    Apache Qpid, using AMQP</div><div>    BEA Weblogic (part of the Fusion Middleware suite) and Oracle AQ from Oracle</div><div>    EMS from TIBCO</div><div>    FFMQ, GNU LGPL licensed</div><div>    JBoss Messaging and HornetQ from JBoss</div><div>    JORAM, from the OW2 Consortium</div><div>    Open Message Queue, from Sun Microsystems</div><div>    OpenJMS, from The OpenJMS Group</div><div>    RabbitMQ, using AMQP</div><div>    Solace JMS from Solace Systems</div><div>    SonicMQ from Progress Software</div><div>    StormMQ, using AMQP</div><div>    SwiftMQ</div><div>    Tervela</div><div>    Ultra Messaging from 29 West (acquired by Informatica)</div><div>    webMethods from Software AG</div><div>    WebSphere Application Server from IBM, which provides an inbuilt default messaging provider known as the Service Integration Bus (SIBus), or which can connect to WebSphere MQ as a JMS provider [5]</div><div>    WebSphere MQ (formerly MQSeries) from IBM</div><br />Ref from:<br />1.http://en.wikipedia.org/wiki/Java_Message_Service<br />2.Spring in Action<br />3.http://goldendoc.iteye.com/blog/1155647<br /><img src ="http://www.aygfsteel.com/caojianhua/aggbug/384095.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/caojianhua/" target="_blank">初一七月</a> 2012-07-26 17:41 <a href="http://www.aygfsteel.com/caojianhua/archive/2012/07/26/384095.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>