- The COM+ Event System
- Event Subscribers
- Event Publishers
- About this Article
Event Publishers
Event publishers are COM+ components that fire events in the form defined by an event class. Creating a publisher is relatively simple after the event class and subscriber are defined. To fire an event, the publisher simply creates an instance of the event class and calls the exposed method. The following code shows how this might happen:
Dim objEvent As OrderSystem.ISendMail Set objEvent = New OrderSystem.ISendMail objEvent.Process "1111", "Floppy Disks", _ "Scot_Hillier@hotmail.com", "ABC123"
Notice how the publisher declares and creates an instance of the event class itself. Normally, creating an instance of an interface will accomplish nothing because the interface has no code. However, COM+ uses this mechanism to decouple the publisher and subscriber. When the publisher calls the Process method, an event is broadcast throughout the COM+ event system. Thus, any component with an active subscription to this event will receive notification.
The LCE system used by COM+ has several advantages beyond simply decoupling the publisher and subscriber. Because of the nature of the system, the number of subscribers can change at any time without changing the code in the publisher. If, for example, you also want to provide shipment notification to the marketing department, the same event can trigger an email message to that department. Furthermore, you can easily enable or disable any combination of subscriptions by using the subscription's property sheet.