ImageVerifierCode 换一换
格式:PPT , 页数:97 ,大小:996.50KB ,
资源ID:1050836      下载积分:10 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-1050836.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(企业级应用系统体系架构EJB0中的MDB.PPT)为本站会员(国***)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

企业级应用系统体系架构EJB0中的MDB.PPT

1、企业级应用系统体系架构 (五) EJB3.0中的 MDB*From:OReilly: Enterprise JavaBeans 3.0, 5th Edition, May.20061Topicn Message-Driven Beansn JMS and Message-Driven Beansn JMS-Based Message-Driven Beansn The Life Cycle of a Message-Driven Beann Connector-Based Message-Driven Beansn Message Linking2JMS and Message-Driven

2、Beansn All EJB 3.0 vendors must support a JMS provider. Most vendors have a JMS provider built in and must support other JMS providers through the JCA. n However, regardless of whether your vendor has its own JMS provider or allows you to integrate some other provider, a JMS provider is an absolute

3、necessity for supporting message-driven beans. n By forcing the adoption of JMS, Sun has guaranteed that EJB developers can expect to have a working JMS provider on which messages can be both sent and received.3JMS as a Resourcen JMS is a vendor-neutral API that can be used to access enterprise mess

4、aging systems. Enterprise messaging systems (a.k.a. message-oriented middleware) facilitate the exchange of messages between software applications over a network. The role of JMS isnt unlike the role of JDBC: just as JDBC provides a common API for accessing many different relational databases, JMS p

5、rovides vendor-independent access to enterprise messaging systems. n Although messaging products arent as familiar as database products, theres no shortage of messaging systems that support JMS, including JBossMQ, IBMs MQSeries, BEAs WebLogic JMS service, Sun Microsystems Sun ONE Message Queue, and

6、Sonics SonicMQ. Software applications that use the JMS API for sending or receiving messages are portable from one JMS vendor to another.n Applications that use JMS are called JMS clients , and the messaging system that handles routing and delivery of messages is called the JMS provider . A JMS appl

7、ication is a business system composed of many JMS clients and, generally, one JMS provider. A JMS client that sends a message is called a producer , and a JMS client that receives a message is called a consumer . A single JMS client can be both a producer and a consumer.n In EJB, enterprise beans of

8、 all types can use JMS to send messages. The messages are consumed by other Java applications or by message-driven beans. JMS facilitates sending messages from enterprise beans using a messaging service , sometimes called a message broker or router. n Message brokers have been around for a couple of

9、 decades-the oldest and most established is IBMs MQSeries but JMS is fairly new, and it is specifically designed to deliver a variety of message types from one Java application to another.4Reimplementing the TravelAgent EJB with JMSn We can modify the TravelAgent EJB so that it uses JMS to alert som

10、e other Java application that a reservation has been made. The following code shows how to modify the bookPassage( ) method so that the TravelAgent EJB sends a simple text message based on a description obtained from the TicketDO object:Resource(mappedName=“ConnectionFactoryNameGoesHere“) private Co

11、nnectionFactory connectionFactory; Resource(mappedName=“TicketTopic“) private Topic topic; Removepublic TicketDO bookPassage(CreditCardDO card, double price) throws IncompleteConversationalState if (customer = null | cruise = null | cabin = null) throw new IncompleteConversationalState( ); try Reser

12、vation reservation = new Reservation( customer, cruise, cabin, price, new Date( ); entityManager.persist(reservation); process.byCredit(customer, card, price); TicketDO ticket = new TicketDO(customer, cruise, cabin, price);5Reimplementing the TravelAgent EJB with JMSn Connection connect = factory.cr

13、eateConnection( ); Session session = connect.createSession(true,0); MessageProducer producer = session.createProducer(topic); TextMessage textMsg = session.createTextMessage( );textMsg.setText(ticketDescription); producer.send(textMsg);connect.close( );return ticket; catch(Exception e) throw new EJB

14、Exception(e); n While all the code we added might look a little overwhelming, the basics of JMS are not all that complicated.6ConnectionFactory and Topicn In order to send a JMS message, we need a connection to the JMS provider and a destination address for the message. A JMS connection factory make

15、s the connection to the provider possible; the destination address is identified by a Topic object. Both the connection factory and the Topic object are obtained by using javax.annotation.Resource to inject these objects directly into the fields of the TravelAgent EJB:Resource(mappedName=“Connection

16、FactoryNameGoesHere“) private ConnectionFactory connectionFactory; Resource(mappedName=“TicketTopic“)private Topic topic; n The ConnectionFactory is similar to a DataSource in JDBC. Just as the DataSource provides a JDBC connection to a database, the ConnectionFactory provides a JMS connection to a

17、message router.n The Topic object itself represents a network-independent destination to which the message will be addressed. In JMS, messages arent sent directly to applications; theyre sent to topics or queues. A topic is analogous to an email list or newsgroup; any application with the proper cre

18、dentials can receive messages from and send messages to a topic. When a JMS client receives messages from a topic, the client is said to subscribe to that topic. JMS decouples applications by allowing them to send messages to each other through a destination, which serves as a virtual channel. A que

19、ue is another type of destination that well discuss in detail later.7Connection and Sessionn The ConnectionFactory is used to create a Connection, which is an actual connection to the JMS provider:Connection connect = connectionFactory.createConnection( );Session session = connect.createSession(true

20、,0); n Once you have a Connection , you can use it to create a Session. A Session allows you to group the actions of sending and receiving messages. In this case, you need only a single Session. Using multiple Sessions is helpful if you wish to produce and consume messages in different threads. Sess

21、ion objects use a single-threaded model, which prohibits concurrent access to a single Session from multiple threads. The thread that creates a Session is usually the thread that uses that Sessions producers and consumers (i.e., MessageProducer and MessageConsumer objects). If you wish to produce an

22、d consume messages using multithreading, you must create a different Session object for each thread.8Connection and Sessionn The createSession( ) method has two parameters:createSession(boolean transacted, int acknowledgeMode) n According to the EJB specifications, these arguments are ignored at run

23、time because the EJB container manages the transaction and acknowledgment mode of any JMS resource obtained from the JNDI ENC. The specification recommends that developers use the arguments true for transacted and 0 for acknowledgeMode, but since they are supposed to be ignored, it should not matter

24、 what you use. Unfortunately, not all vendors adhere to this part of the specification. Some vendors ignore these parameters; others do not.n Its good programming practice to close a Connection after it has been used:Connection connect = factory.createConnection( ); .connect.close( ); 9MessageProduc

25、ern The Session is used to create a MessageProducer, which sends messages from the TravelAgent EJB to the destination specified by the Topic object. Any JMS clients that subscribe to that topic will receive a copy of the message:MessageProducer producer = session.createProducer(topic); TextMessage textMsg = session.createTextMessage( );textMsg.setText(ticketDescription); producer.send(textMsg); 10

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。