《jms框架学习》word版

《jms框架学习》word版

ID:23173701

大小:61.23 KB

页数:22页

时间:2018-11-05

《jms框架学习》word版_第1页
《jms框架学习》word版_第2页
《jms框架学习》word版_第3页
《jms框架学习》word版_第4页
《jms框架学习》word版_第5页
资源描述:

《《jms框架学习》word版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、Jms使用步骤:1.首先需要得到ConnectionFactory和Connection:ConnectionFactoryfactory=newActiveMQConnectionFactory(“vm://localhost”);Connectionconnection=factory.createConnection();2.由Connection创建一个session:Sessionsession=connection.createSession(false,Session.AUTO_ACKNOWLE

2、DGE);3.由Connection创建一个Destination,Destination是指消息发送的目的地,也就是前面说的Queue和Topic,创建好了一个消息后,只需要把这个消息发送到目的地,消息的发送者就可以继续做自己的事情,而不用等待消息被处理完成。至于这个消息什么时候,会被哪个消费者消费,完全取决于消息的接收者。Destinationdestination=session.createQueue(“testObject”);//点到点(P2P)模型//Destinationdestination

3、=session.createTopic(“testObject”);//发布/订阅(Pub/Sub)模型4.创建需要发送的Message:Messagemessage=session.createTextMessage(“Hello,JMS”);5.需要由Session和Destination创建一个消息生产者、发送消息:MessageProducerproducer=session.createProducer(Queue);Producer.send(message);6.创建一个消息消费者来接收这个消

4、息,并使用消息:MessageConsumercomsumer=session.createConsumer(queue);MessagerecyMessage=comsumer.receive();System.out.println(((TextMessage)recyMessage).getText());消息接收可以使用设置消息监听接口comsumer.setMessageListener(newMessageListener());来实现;DevelopingJMSapplicationsYouca

5、ncreateaJMSapplicationusingeitherthepoint-to-pointorthepublish/subscribemessagingmodel.Bothmodelssupportapplicationsthatarecapableof:·CreatingaJMSInitialContextobject·LookingupaConnectionFactoryobject·Creatingpermanentdestinations·Creatingconnections·Creati

6、ngsessions·Creatingmessageproducers·Creatingmessageconsumers·Implementingandinstallingmessagelisteners·Creatingmessages·Sendingmessages·Publishingmessages·Receivingmessages·Browsingmessages·EnablingJMStracing·Closingconnections,sessions,consumers,andproduce

7、rsYoucandownloadacopyoftheJMS1.0.2APIdocumentationfromtheJavaWebsite.CreatingaJMSInitialContextobjectAJMSclientapplicationmustinstantiateaJMSInitialContextobjectandsettheseproperties:·InitialContextfactory–setjava.naming.factory.initialto“com.sybase.jms.Ini

8、tialContextFactory”.·URL–setjava.naming.provider.urltothelocationwheretheclientcanconnecttoEAServer.·Username–validforaconnectionwithEAServer.·Password–validfortheusername.WheninstantiatingaJMSInitialC

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。