Home > Articles

  • Print
  • + Share This
This chapter is from the book

Specifying Other Parts of the Stock Application

The ADF defines the core of the application, but several other pieces are required to make it run. This section briefly describes those pieces as they pertain to the stock application.

The Instance

SQL-NS has the concept of instances, in much the same way that SQL Server does. A SQL-NS instance is a single, named configuration of SQL-NS that can host one or more applications. Each instance is an independent entity that can be started, stopped, and configured on its own. In SQL-NS, an instance is defined by an Instance Configuration File (ICF). The ICF defines the list of applications in the instance (here, just one, the stock application) and the set of delivery channels that applications in the instance can use to send notifications.

This sample's ICF creates an instance called "Chapter03". I've included the text of the ICF in Listing 3.10, but I will not go into an explanation of it here because most of the details are not relevant at this point. Chapter 4, "Instances and the Instance Configuration File," covers the instance concepts and all the elements of the ICF in detail.

Listing 3.10 The ICF That Defines the SQL-NS Instance That Hosts the Stock Application

<?xml version="1.0" encoding="utf-8"?>
<NotificationServicesInstance xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

Event Data

If this were a real application, it would use an event provider that would read and submit real stock data from one of many stock market data publishers. Because this is a sample application, and its purpose is to illustrate the core SQL-NS concepts, not the mechanics of reading from stock market data sources, we'll just submit some sample event data from a file. Chapter 8 covers how to build a real event provider and get events from real sources.

As mentioned in the "Event Collection" section, we'll use the built-in FileSystemWatcher event provider supplied by SQL-NS to get events into the application. The declaration of the FileSystemWatcher event provider shown in Listing 3.7 included a set of runtime arguments. These arguments tell it which filesystem directory to watch and provide a schema for the XML data files that will be dropped in that directory. For this simple stock example, we'll use a sample stock data file that contains a few stock events. Each event specifies a stock symbol and stock price, the fields required by the event class (as you saw in Listing 3.2). You can take a look at a sample event file to see what the data looks like:


All instruction sets in this and future chapters that involve command-line operations begin with a step that instructs you to open a command prompt. This instruction is repeated each time just to ensure that every instruction set is self-contained. You can certainly re-use the same command prompt across different instruction sets if you choose.

  1. Open a Notification Services Command Prompt on your development machine, and navigate to the sample data directory by typing the following command

  2. cd /d C:\SQL-NS\Chapter03\Stock\SampleData
  3. Open the file EventData.xml in Notepad (or your XML editor):

  4. notepad EventData.xml

To submit a batch of events, simply copy this sample data file into the events watch directory.

Entering Subscriptions

Because this is just a sample, we won't build a full subscription management system (doing so would mean building either a Web application or a Win32 application, both of which would distract attention from the core SQL-NS concepts). Instead, we'll just use some VBScripts to enter subscriptions. Internally, these scripts actually use the same APIs that a real subscription management system would use; they just don't provide a fancy user interface.


I'm not going to describe any of the details of the subscription management API until Chapter 7, but if you're curious, you can follow these instructions to view the code in the VBScripts we'll be using in this chapter:

  1. Open a Notification Services Command Prompt on your development machine and navigate to the Chapter 3 scripts directory by typing the following command:

  2. cd /d C:\SQL-NS\Chapter03\Scripts
  3. Open the file AddSubscribers.vbs in Notepad using the following command (or you can use another editor if you prefer). As the name suggests, this is the VBScript that adds a set of subscribers to the instance.

  4. notepad AddSubscribers.vbs

  5. Go back to the command prompt and navigate to the Chapter03\ Stock\SampleData subdirectory using the following command:

  6. cd ..\Stock\SampleData

  7. Open the file AddStockSubscriptions in Notepad using the following command (or use any other editor if you prefer). This is the VBScript that adds a set of stock subscriptions to the application.

  8. notepad AddStockSubscriptions.vbs

Seeing the Final Notifications

After raw notification data is generated, it gets formatted and then delivered. In this sample, we'll use the built-in XsltFormatter content formatter provided by SQL-NS that turns the raw notification into a readable message using an XSL transform. Even though the XSLT formatter is often used in real SQL-NS applications, I'll defer explaining how it works until Chapter 9, "Content Formatters."

On the delivery side, this sample application uses another SQL-NS built-in component: the File Delivery Protocol. This component "delivers" the notifications to a file. You can then check the output of the application simply by opening this file. In a real application, you'd probably use several different delivery protocols that could send the notification messages via email, or as text messages to cell phones, for example. Chapter 10 describes all the built-in SQL-NS delivery protocols and shows how you can build your own custom delivery protocol.

  • + Share This
  • 🔖 Save To Your Account