




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年电工安全操作考试试卷及答案
- 2025建筑施工八大员综合知识考试题库及答案
- 合同法律效力评估考核试卷
- 新建生产吸尘器、家用电器配件、汽车零部件项目环境影响评价报告表
- 2025年成都市锦江区(中小学、幼儿园)教师招聘试题及答案
- 住宅建筑雨水收集与利用系统设计考核试卷
- 儿童玩具行业国际市场风险预警系统构建考核试卷
- 应急响应团队建设与管理考核试卷
- 年产纸盒800万个生产项目沃美生物配套实验室项目报告表
- 2024江西水利职业学院招聘笔试真题及参考答案详解
- 2025年高考天津卷数学真题(原卷版)
- 执业药师资格考试《中药学综合知识与技能》真题及答案(2025年新版)
- 单位工作群管理制度
- 公益岗考试题库及答案
- 亚低温治疗的试题及答案
- 《光伏电站项目全过程管理手册》(第三分册:施工、验收、运维)
- 养生馆承包合同协议书
- 物业管理保修管理措施
- 胃息肉个案护理要点
- 【祈飞观察】抖音2024年篮球鞋品类趋势洞察224mb
评论
0/150
提交评论