Sdílet prostřednictvím


Lesson 4: Adding a Notification Class

In this lesson, you will add a notification class to the application definition file (ADF) and then update the instance of Notification Services to apply the changes to the application database. You can then review the changes made to the application database.

Notification Class Primer

A notification class represents one type of notification produced by your Notification Services application. When you define a notification class, you define the following information:

  • Fields for the notification data, including the data types. These fields define the data you will be sending to subscribers.
  • Information about the content formatter used to format notifications for the notification class. You can use the built-in Extensible Stylesheet Language Transformations (XSLT) content formatter, or you can use a custom content formatter.
  • Information about how delivery protocols are to be used to deliver notifications.

You can also define optional settings such as digest or multicast delivery and the notification expiration age. For more information about notification classes, see Defining Notification Classes.

When you create or update the application, Notification Services uses the notification class definition to create tables, views, indexes, and stored procedures for storing and managing notification data.

When you create the notification table and view, Notification Services adds the following fields: SubscriberId, DeviceName, and SubscriberLocale. These fields are required by Notification Services, and are described in later lessons.

The WeatherAlerts Notification Class

For this application, you will add a WeatherAlerts notification class to the ADF. This notification class has five notification fields, an XSLT content formatter, and a File delivery protocol.

  • The notification fields are City, Date, Low, High, and Forecast. In this application, the notification class fields match the event class fields, but this is not required.

  • When Notification Services distributes the notifications, it will format the raw data into a customized message using the built-in XSLT content formatter. The XSLT file name is WeatherTransform.xslt, and the file location is defined by the %_AppPath_% parameter; the value for this parameter is provided in the ICF.
    For more information about the XSLT content formatter, see XSLT Content Formatter.

  • After formatting, Notification Services will deliver the notifications to a file by using the built-in File delivery protocol. The file name and location are defined in the DeliveryChannels element of the ICF.
    Protocol definitions can contain field definitions for message headers, such as those required by SMTP, and protocol execution settings to configure retry, failure, and time-out settings. The File protocol does not use these settings, but most other protocols use header fields.

    Note

    The File delivery protocol is intended primarily for prototyping and testing.

Add the Notification Class XML to the ADF

The XML in this section defines the notification class. Examine the XML and then follow the instructions to copy the XML to the ADF.

Add the Notification Class XML to the ADF

  1. Click Copy Code to copy the XML to the Windows Clipboard.

    <!-- Notification Classes -->
    <NotificationClasses>
      <NotificationClass>
        <NotificationClassName>
          WeatherAlerts</NotificationClassName>
        <Schema>
          <Fields>
            <Field>
              <FieldName>City</FieldName>
              <FieldType>nvarchar(35)</FieldType>
            </Field>
            <Field>
              <FieldName>Date</FieldName>
              <FieldType>datetime</FieldType>
            </Field>
            <Field>
              <FieldName>Low</FieldName>
              <FieldType>float</FieldType>
            </Field>
            <Field>
              <FieldName>High</FieldName>
              <FieldType>float</FieldType>
            </Field>
            <Field>
              <FieldName>Forecast</FieldName>
              <FieldType>nvarchar(3500)</FieldType>
            </Field>
          </Fields>
        </Schema>
        <ContentFormatter>
          <ClassName>XsltFormatter</ClassName>
          <Arguments>
            <Argument>
              <Name>XsltBaseDirectoryPath</Name>
              <Value>%_AppPath_%</Value>
            </Argument>
            <Argument>
              <Name>XsltFileName</Name>
              <Value>WeatherTransform.xslt</Value>
            </Argument>
          </Arguments>
        </ContentFormatter>
        <Protocols>
          <Protocol>
            <ProtocolName>File</ProtocolName>
          </Protocol>
        </Protocols>
      </NotificationClass>
    </NotificationClasses>
    
  2. In Solution Explorer, open WeatherADF.xml.

  3. Replace the following XML with the XML you just copied.

    <!-- Notification Classes -->

    <NotificationClasses></NotificationClasses>

  4. On the File menu, select Save WeatherADF.xml.

Update the Instance of Notification Services

After you modify the ADF, you update the instance of Notification Services to add notification class objects to the application database:

To update the instance of Notification Services

  1. In Object Explorer, expand Notification Services.

  2. Right-click Tutorial, point to Tasks, and then select Update.

  3. In the Update Instance dialog box, click Browse, locate the TutorialICF.xml file, and then click Open.

  4. In the Parameters grid, review the values for the parameters. Use the same values you used to create the instance.

  5. Click OK.

  6. Review the Notification Services - Update Summary dialog box, and then click Update.

  7. When the update actions are complete, click Close.

Review the Database Changes

When you update the instance, Notification Services adds tables, views, and stored procedures for the notification class in the TutorialWeather application database.

  • The dbo.WeatherAlerts view is where the notification generation rules will insert notifications.

  • The dbo.NSWeatherAlertsFileNotifications view contains notifications from the WeatherAlerts notification class sent using the File delivery protocol. This view is for internal use only.

  • The dbo.NSWeatherAlertsNotificationDistribution view combines data from several internal Notification Services tables to provide information about notification distribution attempts.

  • The dbo.NSWeatherAlertsNotifications table is the underlying table that contains notification data for the notification class. Notification data stays in this table until it is removed by the vacuumer data removal process. This table is for internal use only.

    Warning

    Do not directly modify data in the notification tables and views.

You can use Object Explorer to examine these objects in the TutorialWeather database. Tables and views for internal use only contain data that is used for internal operations; you do not have to understand this data.

You may have to refresh Object Explorer to see the new objects.

Next Lesson

Lesson 5: Adding a Subscription Class

See Also

Concepts

Notification Services Tutorial

Other Resources

Defining Event Classes
Building Notification Solutions
Introducing SQL Server Notification Services

Help and Information

Getting SQL Server 2005 Assistance