Tài liệu Module 5: Queued Components and Events pptx

110 435 0
Tài liệu Module 5: Queued Components and Events pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Contents Overview 1 Introduction to Queued Components 2 Working with Queued Components 16 Lab 5.1 Creating and Using Queued Components 35 Handling Events 39 Publisher and Subscriber Architecture 45 Working with Events 53 Lab 5.2: Creating and Using Event Classes 71 Combining Queued Components and Events 77 Lab 5.3: (Optional) Combining Queued Components and Events 83 Best Practices 90 Review 93 Module 5: Queued Components and Events Information in this document is subject to change without notice. The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted. Complying with all applicable copyright laws is the responsibility of the user. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation. If, however, your only means of access is electronic, permission to print one copy is hereby granted. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.  2000 Microsoft Corporation. All rights reserved. Microsoft, BackOffice, MS-DOS, Windows, Windows NT, ActiveX, MSDN, PowerPoint, and Visual Basic are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted. Other product and company names mentioned herein may be the trademarks of their respective owners. Module 5: Queued Components and Events iii Instructor Notes In this module, students will learn how to implement asynchronous functionality by using queued components in a COM+ application. Students will also learn how to use the COM+ Event service to match and connect applications that publish information with subscribers. For advanced students, material is also provided to learn how to combine queued components and events. After completing this module, students will be able to: ! Describe the purpose and benefits of queued components. ! Create a queued component. ! Instantiate and communicate with a queued component. ! Describe the COM+ Events service provided with Microsoft Windows 2000. ! Create and use an event class to match publishers with subscribers. ! Combine queues with events to make the processing of publisher and subscriber events time independent. In the practice, students will learn to enable an application for queuing and view application queues by using the computer management tool. ,Instructor-led demonstrations are provided to illustrate how to create and register an event class, create a subscriber component and add a subscription entry to COM+, publish events, and finally filter events. A demonstration is also provided to illustrate how queued components can be combined with events to publish and deliver events asynchronously. In the first lab, students will use COM+ queued components to place orders asynchronously. In the second lab, they will use the COM+ events to create and register an event class. In the optional lab, students will learn how to combine queued components and events to make publisher and subscriber events time independent. iv Module 5: Queued Components and Events Materials and Preparation This section provides you with the required materials and preparation tasks that are needed to teach this module. Required Materials To teach this module, you need the following materials: ! Microsoft PowerPoint file 1907A_05.ppt ! Module 5: Queued Components and Events ! Lab 5.1: Creating and Using Queued Components ! Lab 5.2: Creating and Using Event Classes ! Lab 5.3: (Optional) Combining Queued Components and Events ! Animation: "COM+ Queued Components" on the Student CD-ROM, file 1907A_05a005.avi ! Animation: "COM+ Events" on the Student CD-ROM, file 1907A_05a010.avi Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module. ! Complete the practice, demonstrations, and labs. ! Read the instructor notes and the margin notes for the module. Module Strategy Use the following strategy to present this module: ! Introduction to Queued Components Discuss the inherent problems associated with synchronous communications in a distributed environment and highlight how a message-based form of asynchronous communications, such as COM+ queued components, can overcome many of these problems. The primary challenge is to provide a reliable way for the various parts of an application to communicate. Other issues that you should consider include unreliable or slow network connections, remote disconnected users, and heterogeneous application architectures. Discuss how queued components relate to the underlying Microsoft Message Queue Server (MSMQ) technology. Present the architecture of queued components and discuss the three system-provided components: the recorder, the listener, and the player. Point out the restrictions on interface design required by queued components. ! Working with Queued Components Discuss how to use queued components to manage the communication that occurs between the various parts of an enterprise application. Explain how to view, instantiate, and create queued components. Discuss how to communicate with and receive output from queued components. Finally, describe how to use the COM+ queued component service to handle transactions and security. Module 5: Queued Components and Events v Use the practice to show how to create a queued component and enable a COM+ application for queuing by using the Component Services tool. After the component is created, show how to use the Computer Management tool to view the application’s queues. ! Handling Events Explain that one of the classic challenges in computer programming is determining the best way to notify interested entities that information or data has changed. A number of possible solutions exist, each with varying degrees of flexibility and suitability. One of the key factors that you need to consider is how tightly the publisher (the notifier) and subscriber (the entity to be notified) should be coupled when handling events. Discuss the polling approach (ill-suited to a distributed environment) and tightly coupled approaches such as Visual Basic events that are based on the COM connection point mechanism and loosely coupled events such as the COM+ events. Discuss the advantages and disadvantages of each. Generally, the looser the coupling, the more adaptable and flexible the solution. ! Publisher and Subscriber Architecture Discuss how the publisher and subscriber architecture adopted by the COM+ Event service uses two key components. First, an event class is used to represent the connection between a publisher and subscriber. Second, the COM+ Event Store within the COM+ catalog is used as a database for subscriptions. Explain that the COM+ Event service is used to advertise and deliver information to one or more interested parties without a prior knowledge of their identity. The COM+ Event service acts as an intermediary between information publishers and subscribers. As an intermediary, the COM+ Event service addresses some of the weaknesses associated with other methods for handling COM events, such as the tight coupling approach used in Visual Basic. Explain the critical role of the event class and that subscribers must implement the interfaces exposed by the event class. Also explain that the system provides an implementation of the event class, which searches the event store and forwards event notifications to each subscriber in turn. ! Working with Events Explain how to create and register event classes, subscribe to events, and publish events. Events can also be filtered so that subscribers can be selective about what events they should receive. Discuss the two primary methods of filtering: subscriber filtering and publisher filtering. Explain the advantages of declarative publisher filtering over run-time publisher filtering (that is, the ability to use the solution with queued components and the fact that the publisher code does not need to be modified). vi Module 5: Queued Components and Events ! Combining Queued Components and Events Discuss how the COM+ Event service can be combined with the Queued Component service to make the publisher and subscriber time independent. Events can be published asynchronously (by queuing between publisher and event object) or events can be delivered asynchronously (by queuing between event object and subscriber). Developers should choose where to introduce queuing based on the business logic used in their application. It is also possible to use a queuing mechanism in both places. Discuss how asynchronous communications can affect the order in which events are delivered. ! Best Practices Review the key points covered in the module and summarize the best practices as part of your summary. In most cases, the module covers a practical way to observe each of the best practices mentioned. Multimedia Presentation This section provides multimedia presentation procedures that do not fit in the margin notes or are not appropriate for the student notes. COM+ Queued Components This animation presents the architecture of the queued component service. It illustrates the role of the three system-provided components: the recorder, the listener, and the player. It also covers how they work together to provide the complete solution. ! To prepare for the multimedia presentation ! To show this animation, double-click the file 1907A_05a005.avi. COM+ Events This animation presents the architecture of the COM+ Event service. It shows the event class acting as an intermediary between the publisher and subscriber, and providing the loose coupling. It also illustrates how the publisher fires events by calling methods on the event class interface, and how these events are forwarded by the system-provided implementation code within the event class onto each subscriber registered in the COM+ Event Store. It also highlights that each subscriber must provide an implementation of the event interface to “handle” each event. ! To prepare for the multimedia presentation ! To show this animation, double-click the file 1907A_05a010.avi. Module 5: Queued Components and Events vii Demonstrations This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes. These instructions assume that the demonstrations will be performed in sequence. Queued Components The purpose of this demonstration is to show how to enable an application and a component for queuing and to show how the Queue moniker is used to instantiate a queued component. ! To perform the demonstration 1. Open the project QCServer.vbp located in <install folder>\Democode\Mod05\Queued Components\Server. Describe to the students how the Server class module contains one method that simply displays the supplied message via a message box. 2. Select Make QCServer.dll from the File menu to generate the QCServer component. 3. Using the Component Services tool, create a COM+ application called QC Server. Select all the default options. 4. Install the QCServer.dll component into the QC Server application. 5. Select and then right-click the application and select Properties. 6. On the Queuing page, place a check mark in the Queued and Listen check boxes. Reiterate the point that the Queued and Listen options cause the creation of a set of queues for the application that enables the listener to detect inbound messages when the application is running. 7. Click OK to dismiss the Properties dialog box. 8. Expand the QC Server Components folder and then expand the Interfaces folder beneath QCServer.Server. 9. Select then right-click the _Server interface and select Properties. 10. On the Queuing tab of the Properties dialog box, place a check mark in the Queued check box. Explain that this informs COM+ to expect queued messages to be received for methods on this interface. 11. Press OK to dismiss the Properties dialog box. 12. Open the project QCTestHarness.vbp in <install folder>\Democode\Mod05\Queued Components\Client. 13. Examine and explain the code behind the Send Message button. Explain that this code creates an instance of the QCServer.Server component by using GetObject and the Queue moniker, which results in a reference to a recorder object. Highlight the fact that despite the subtle change in the way that the component is instantiated, object interaction following instantiation is performed in the standard manner. In this case, the SendMessage method is called with a single string parameter. Note viii Module 5: Queued Components and Events 14. Run the QC Test Harness application and press the Send Message button. 15. Nothing visible will happen at this point because the QCServer application is not currently running. However, point out that a message will have been delivered to the QCServer application’s queue. 16. Press the Send Message button again to generate a second message. 17. Using the Computer Management tool, view the contents of the QCServer’s application queue. Two messages will currently be in the queue. 18. Using the Component Services tool start the QCServer application. 19. Two message boxes will be displayed that contain the text parameter passed from the test harness: “Hi There!” Explain that the listener component within the QC Server application detected the messages in the queue, dequeued them, forwarded them to the player (which then instantiated the QCServer object), and called the method. 20. Click OK to dismiss both message boxes. Creating and Registering an Event Class The purpose of this demonstration is to show how to create an event class by using an ActiveX DLL project and an abstract class module. The purpose of the class module is to simply define each function in the event class interface. Having created the event class DLL, this demonstration shows how to install the event class component into a COM+ application. This demonstration uses a simplified version of an event class that might be used by an Electronic Point of Sale (EPOS) stock management system. As such, the event interface provides two methods: LastItemSold and NewOrderPlaced. ! To perform the demonstration 1. Open the stock event class project StockEventClass.vbp located in <install folder>\Democode\Mod05\Events\EventClass. 2. Describe to the students that the IStockEvents class module is an abstract class module in that it contains public functions definitions but no implementation code. Point out that the system will provide implementation code when the event class is instantiated by a publisher. Also mention that subscribers ultimately must provide concrete implementation code for each function in the interface to “handle” each event. 3. Select Make StockEventClass.dll from the File menu to generate the event class DLL. Ensure students are aware that this option simply creates a DLL containing a type library that contains the IStockEvents interface definition. You have not supplied any code. 4. By using the Component Services tool, create a new COM+ application called EPOS Stock Events. Take all the default options when creating the application. This application will be used to contain the event class. 5. Now install the StockEventClass.dll as an event class into the EPOS Stock Events application. Demonstrate that installing an event class component in an application is a similar procedure to adding a normal component, except that the Install new event class(es) button must be used. Module 5: Queued Components and Events ix 6. Show students that the event class is listed beneath the Components folder and looks like a regular component. The only discernable difference is on the Advanced page of the component’s Properties dialog box. Show this page and illustrate the presence of the LCE group box. At this point, you can reiterate the purpose of the Fire in parallel option. 7. You have now created and registered an event class. Now you need some subscribers. 8. Return to the Microsoft PowerPoint slides to discuss subscribers. Subscribing To Events The purpose of this demonstration is to show how to create subscriber components by creating ActiveX DLL projects. You will create the DLL project with class modules that use the Implements keyword to provide a concrete implementation of the event class interface. The demonstration proceeds to show how subscription records are entered into the COM+ Event Store. Two subscribers are provided. ! To perform the demonstration 1. Open the first event subscriber project EventSubscriber.vbp located in <install folder>\Democode\Mod05\Events\Subscriber. 2. View the StockEventSubscriber class module and illustrate the use of the Implements keyword. Point out that the class module must provide concrete implementations for all of the methods defined in the interface being implemented. Also highlight the fact that a project reference has been set to the StockEventClass type library. 3. Select Make EventSubscriber.dll from the File menu to build the subscriber component. 4. Repeat the previous three steps for the EventSubscriber2.vbp project. This process will create a second subscriber component. (When these subscribers are called, the resulting message boxes displayed by their implementation code will reflect the identity of each subscriber by displaying the appropriate subscriber number in the message box title bar). 5. By using the Component Services tool, create a new COM+ application called EPOS Subscriber. Select the default options when creating this application. 6. Add the two subscriber components to the application by using the regular Install new component(s) button of the Component Install Wizard. 7. Expand both components within the Component Services tree view to display the two Subscriptions folders. 8. You will now create a new subscription record in the COM+ Event Store. Select the Subscriptions folder of the first subscriber, right-click, point to New, and then point to Subscription. 9. Select the _IStockEvents interface from the list displayed by the New Subscription Wizard. Point out that by selecting an individual method at this time, a subscription to a single method may be created. 10. Click Next and wait for the StockEventClass.IStockEvents ProgID to be displayed in the Select Event Class dialog box. x Module 5: Queued Components and Events 11. Select this ProgID and click Next. 12. Enter a suitable description for the subscription such as “First EPOS Event Subscription.” 13. Place a check mark in the Enable this subscription immediately check box and then click Next and Finish to create the subscription. Point out that a persistent subscription has now been registered in the COM+ Event Store. This subscription will survive system restarts. 14. Repeat the steps 8 to 13 to create a subscription for the second subscriber component. 15. Two subscription records now exist in the COM+ Event Store. All you need now is a publisher application. 16. Return to the PowerPoint slides to discuss publishers and how to publishing events. Publishing Events The purpose of this demonstration is to show how to create an application that publishes events. The stock event publisher application creates an instance of the stock event class and fires the appropriate event method, depending on which button is pressed. One button fires the LastItemSold event while the other fires the NewOrderPlaced event. ! To perform the demonstration 1. Open the stock event publisher project StockEventPublisher.vbp located in <install folder>\Democode\Mod05\Events\Publisher. 2. Show the application’s main form and explain that the Item Sold button fires a LastItemSold event while the Product Ordered button fires a NewOrderPlaced event. 3. Explain that the Publish Asynchronously check box is used in a future demonstration when events are intended for asynchronous publication using queued components. (For the current demonstration, you should leave this check box unselected). 4. Examine and explain the code behind each button. Explain that to publish an event, you must create an instance of the event class and then call methods on the event class’s interface to fire events. The event class is created in the CreateEventObject private function because this approach allows control over whether the object is created in the standard fashion (by using the New keyword) or created via a Queue moniker for asynchronous method publication. (This determination is made by setting the Publish Asynchronously check box). 5. Select an item from the Products list and click the Item Sold button. 6. A message box will be displayed with the title box indicating which subscriber has been invoked. (Beware that the message box may not come to the foreground and may appear on the task bar). 7. Click OK to remove the message box. 8. A second message box from the other subscriber will appear. Click OK to remove this message box. Stress that the order of delivery is determined by the system, and if the order of delivery is important, you will have to write a publisher filter component. [...]... Module 5: Queued Components and Events 1 # Overview Slide Objective ! Lab 5.1: Creating and Using Queued Components ! Handling Events ! Publisher and Subscriber Architecture ! Working with Events ! Lab 5.2: Creating and Using Event Classes ! Combining Queued Components and Events ! Lab 5.3: (Optional) Combining Queued Components and Events ! In this module, you will learn how to use COM+ queued components. .. retrieve and process any awaiting messages Module 5: Queued Components and Events Animation: COM+ Queued Components Delivery Tip Play COM+ Queued Components animation that shows the Recorder, Listener, and Player objects working together to deliver a message 15 16 Module 5: Queued Components and Events # Working with Queued Components ! Developing a Queued Component ! Practice: Creating and Viewing Queued. .. Component ! Demonstration: Working with Queued Components ! Receiving Output from Queued Components ! Queued Components and Transactions ! Queued Components and Security Module 5: Queued Components and Events 17 Developing a Queued Component ! Create regular COM+ component $ Subject to interface restrictions ! Create COM+ application ! Mark application as queued $ Queued and Listen check boxes $ COM+ creates... ! Create and use an event class to match publishers with subscribers Combine queues with events to make the processing of publisher and subscriber events time independent 2 Module 5: Queued Components and Events # Introduction to Queued Components ! Asynchronous Communication ! Microsoft Message Queue Server vs Queued Components ! Architecture of Queued Components ! Animation: COM+ Queued Components. .. Output from Queued Components in this module Module 5: Queued Components and Events The primary benefit of using asynchronous communication in this scenario is that end users do not have to wait for a response if it is not required The response may take a long time because of potential network latency or server unavailability 7 8 Module 5: Queued Components and Events Message Queuing vs Queued Components. .. by this component to other components Note The Queued check box will not be enabled if the interface has any associated ByRef parameters For more information about interface restrictions for queued components, see "Interface Design Issues" in Message Queuing vs Queued Components in this module Module 5: Queued Components and Events 21 Practice: Creating and Viewing Queued Components In this practice,... to view, instantiate, and create queued components You will also learn how to communicate with and receive output from queued components Finally, you will also learn how the COM+ Queued Component service handles transactions and security This section includes the following topics: ! Developing a Queued Component ! Practice: Creating and Viewing Queued Components ! Instantiating a Queued Component ! Demonstration:... then expand the Components folder Module 5: Queued Components and Events xiii 19 Expand the first subscriber component (EventSubscriber.StockEventSubscriber) and expand its Subscriptions folder to show the First EPOS Event Subscription 20 Select and then right-click the First EPOS Event Subscription, and select Properties 21 On the Options tab, place a check mark in the Queued check box Explain that this... Issues" in Message Queuing vs Queued Components in this module 2 Create a COM+ application by using the Component Services administration tool 3 Mark the COM+ application as queued 18 Module 5: Queued Components and Events From the Application Properties dialog box, select the Queuing tab and check the Queued and Listen boxes as shown in the following illustration • Checking the Queued box causes COM+ to... Components ! Developing a Queued Component ! Practice: Creating and Viewing Queued Components ! Instantiating a Queued Component ! Demonstration: Working with Queued Components ! Receiving Output from Queued Components ! Queued Components and Transactions ! Queued Components and Security In an enterprise solution, you can use queued components to manage the communication that occurs between the various parts . with queued components and the fact that the publisher code does not need to be modified). vi Module 5: Queued Components and Events ! Combining Queued Components. filtering. xii Module 5: Queued Components and Events Combining Queued Components with Events The purpose of this demonstration is to show how queued components

Ngày đăng: 21/12/2013, 19:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan