




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Topics:
JMS&JavaMailChin-YiTsai1JMSJMS提供一種可以在J2EE程式和元件間傳送訊息的方式MessageagentJ2EE應用程式和元件使用JMSAPI和JMS溝通JMS由五個元素所組成ProviderClientMessageAdministeredobject:designationfactory,connectionNativeserver2訊息傳遞架構Point-to-point同步Subscriber/publisher3Point-to-PointMessagingClient1Client2QueuesendsacknowledgesconsumesMsgMsg4Publish/SubscribeMessagingClient1Client2publishessubscribessubscribesMsgTopicClient3deliversdelivers5ThebasicbuildingblocksofaJMSapplicationAdministeredobjectsconnectionfactoriesanddestinationsConnectionsSessionsMessageproducersMessageconsumersMessages6JMSAPIProgrammingModelConnectioncreatescreatescreatesMsgDestinationreceivesfromsendstoConnectionFactoryDestinationMessageConsumerSessionMessageProducercreates7JMSMessageTypesMessageTypeContainsSomeMethodsTextMessageStringgetText,setTextMapMessagesetofname/valuepairssetString,setDouble,setLong,getDouble,getStringBytesMessagestreamofuninterpretedbyteswriteBytes,readBytesStreamMessagestreamofprimitivevalueswriteString,writeDouble,writeLong,readStringObjectMessageserializeobjectsetObject,getObjectMessageFormat
MessageHeaderMessagePropertiesMessageBody8javax.jmsPackageConnectionEncapsulatesavirtualconnectionwithaJMSAPIproviderSessionSingle-threadedcontextforproducingandconsumingmessagesQueueSenderAnobjectcreatedbyasessionusedforsendingmessagestoaqueueQueueReceiverAnobjectcreatedbyasessionusedforreceivingmessagesfromaqueue9CreatingaPoint-to-PointJMSAPIApplication1.LookupaConnectionfactoryusingtheJ.N.D.I.API.2.LookupthemessagequeueusingtheJ.N.D.I.API.3.CreateaConnectionusingthefactory.4.CreateaSessionobject.5.CreateaMessageSenderobject.6.CreateoneormoreMessageobjects.7.SendoneormoreMessageobjectsusingtheMessageSenderobject.8.SendacontrolmessagetotheQueueobjectthatallmessageshavebeensent.10try{ INitialContextjnidiContext=newInitialContext();
queueConnectionFactory=(QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory"); queue=(Queue)jndiContext.lookup(queueName);
queueConnection=queueConnectionFactory.createQueueConnection();
queueSession=queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueSender=queueSession.createSender(queue);
message=queueSession.createTextMessage(); message.setText("Thisisasimplemessage”); queueSender.send(message); queueConnection.close();}catch(JMSExceptione){ System.out.println("Exceptionoccurred:"+}Sendmessage11try{ InitialContextjndiContext=newInitialContext(); factory=(QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory"); queue=(Queue)jndiContext.lookup(queueName); QueueConnectionconnection=factory.createQueueConnection(); QueueSessionsession=connection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE);
receiver=session.createReceiver(queue);
receiver.setMessageListener(newMessageListener(){ publicvoidonMessage(MessagenewMessage){ try{
TextMessagemessage=(TextMessage)newMessage; System.out.println("Messagereceived"); System.out.println(message.getText());
message.acknowledge(); }catch(Exceptione){} } }); connection.start();}catch(JMSExceptione){}catch(NamingExceptione){}Receivemessage12CreatingaPublish/SubscribeJMSAPIApplication1.LookupaTopicConnectionfactoryusingtheJ.N.D.I.API.2.LookupaTopicobjectusingtheJ.N.D.I.API.3.CreateConnectionandSessionobjects.4.CreateaTopicPublisherobject.5.CreateoneormoreMessageobjects.6.PublishoneormoremessagesusingtheTopicPublisherobject.13try{ topicConnectionFactory=(TopicConnectionFactory) jndiContext.lookup("TopicConnectionFactory"); topic=(Topic)jndiContext.lookup(topicName);
topicConnection=topicConnectionFactory.createTopicConnection();
topicSession=topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topicPublisher=topicSession.createPublisher(topic);
message=topicSession.createTextMessage(); message.setText("Thisisasimplepublish/subscribemessage”); topicPublisher.publish(message);}catch(JMSExceptione){ System.out.println("Exceptionoccurred:"+e.toString());}Publisher14try{ TopicConnectionFactoryfactory=(TopicConnectionFactory) jndiContext.lookup("TopicConnectionFactory"); topic=(Topic)jndiContext.lookup(topicName); TopicConnectionconnection=factory.createTopicConnection(); TopicSessionsession=connection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);
subscriber=session.createSubscriber(topic);
subscriber.setMessageListener(newMessageListener(){ publicvoidonMessage(MessagenewMessage){ try{ TextMessagemessage=(TextMessage)newMessage; System.out.println("Messagereceived"); System.out.println(message.getText());
message.acknowledge(); }catch(Exceptione){} } });
connection.start();}catch(JMSExceptione){}Subscriber15JavaMail16JavaMailAPI傳送電子郵件接收電子郵件刪除電子郵件回覆和發送一封電子郵件發送電子郵件傳送附加檔案接收附加檔案搜索一個電子郵件資料夾17JavaMailAPIPackagejavax.mailClassesmodelingamailsystem.javax.mail.eventListenersandeventsfortheJavaMailAPI.ernetClassesspecifictoInternetmailsystems.javax.mail.searchMessagesearchtermsfortheJavaMailAPI.18ImportantClassesjavax.mail.SessionJavax.mail.MessageJavax.mail.AddressJavax.mail.AuthenticatorJavax.mail.TransportJavax.mail.StoreJavax.mail.Folder19MainJavamailmainclassesMessageSessionFolderTransportConnectiontoserverSendingmail
usingSMTPReceivingmailusing
POPorIMAPStoreConnectionto
aremovemailfolder
(mainlytheINBOX)Receiveandarray
ofmessagesSendingamessage收送20傳送電子郵件Session sendMailSession;
Store store;
Transport transport;
Propertiesprops=newProperties();
sendMailSession=Session.getInstance(props,null);
props.put("mail.smtp.host","");
MessagenewMessage=newMimeMessage(sendMailSession);
newMessage.setFrom(newInternetAddress(request.getParameter("from")));
newMessage.setRecipient(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 世界结合病日活动方案
- 业余足球队比赛活动方案
- 培训公司策划方案
- 大公司七夕节活动方案
- 大学推优活动方案
- 培育专项活动方案
- 地产入户活动方案
- 大宝室内游戏活动方案
- 天津骑行活动方案
- 地产公司质量月活动方案
- 人事行政部2025年部门工作总结模版
- 2025年庆祝建党104周年党章知识竞赛测试题库及答案(共50题)
- 2025山煤国际井下岗位高校毕业生招聘300人(山西)笔试参考题库附带答案详解
- 生物安全培训知识课件
- 2023版《护理分级标准》解读
- 2025年贵州省普通高中学业水平模拟考试物理试卷
- 新疆维吾尔自治区2024年普通高校招生单列类(选考外语)本科一批次投档情况(文史)
- 委托收款协议书模板
- 信息系统的使用与维护管理制度
- 常州保安证考试题及答案
- 全国中小学生学籍信息管理系统用户操作手册(学校级)
评论
0/150
提交评论