- The COM+ Event System
- Event Subscribers
- Event Publishers
- About this Article
Event Subscribers
When the event class is installed, you need to create a subscriber to receive the new event and implement the interface defined by the event class. In this implementation, the subscriber defines the actions for the event. In this case, you use the Collaborative Data Objects (CDO) to send the mail. Listing 1 shows how the subscriber implements the interface defined by the event class.
Listing 1: Subscriber Implementation
Implements ISendMail Private Sub ISendMail_Process( _ ByVal strProductID As String, _ ByVal strDescription As String, _ ByVal strEMail As String, _ ByVal strTracking As String) 'Author: Scot P. Hillier 'Purpose: Send E-Mail 'Revisions: 5/9/00 Original Dim objMail As CDONTS.NewMail Set objMail = New CDONTS.NewMail objMail.From = "sales@xyz.com" objMail.To = strEMail objMail.Subject = "Order Update" objMail.Body = "Product " & strProductID & ": " _ & strDescription & " shipped under tracking number " _ & strTracking objMail.Send End Sub
After you implement the interface, the subscriber must be placed in a COM+ application by using the Component Install Wizard. However, after the component is installed, you must establish the subscription with the COM+ event system.
Each component in a COM+ application has a Subscriptions folder beneath it that contains information about all events that your component will receive. To create a new subscription, select the folder and choose New and then Subscription from the Action menu to start the New Subscription Wizard. First, you have to select the method that will receive events (see Figure 3). For this example, the method is Process.
Select the method to receive the event.
When the method name is selected, Component Services prompts you to identify the event class associated with that interface. Because your event system might have several event classes that define an interface compatible with your subscriber, COM+ needs to know specifically which one to associate with the subscription. Figure 4 shows how to select the event class in the wizard.
Select the event class to associate with the subscription.
Finally, COM+ prompts you to provide a name for the new subscription and gives you a chance to enable the subscription and allow your subscriber to receive events immediately. Otherwise, you can use the COM+ Catalog Administration objects to enable the subscription. Figure 5 shows the final settings for the subscription.
Name the subscription and enable event notification.
After running the wizard, you will see a new entry in the Subscriptions folder indicating that the subscriber is ready to receive events from the COM+ event system. The only thing left to do is to create a publisher.