A condition action allows for flexible rules created by subscribers. While a predefined action only permits subscribers to specify parameter values for developer-defined queries, a condition action allows a subscriber to create the equivalent of a WHERE clause for the query, using Boolean operators (AND, OR, and NOT) to combine individual conditions.
For example, a weather application might have an event class that contains two fields: City and Forecast. The developer can define a basic query to create notifications, such as this:
INSERT INTO dbo.WeatherNotifications(SubscriberId, DeviceName,
SubscriberLocale, City, Forecast)
SELECT [Subscription.SubscriberId], [Subscription.DeviceName],
[Subscription.SubscriberLocale], [Input.City], [Input.Forecast])
FROM dbo.FlightEventRule
Notice that this selects data from a view named after the rule (in this case, FlightEventRule). The fields in that view are named Subscription.SubscriptionFieldName and Input.EventFieldName, which requires the field names to be surrounded by square brackets.
Through a subscription management interface, a subscriber can define conditions that are equivalent to a WHERE clause. For example, a user can specify two conditions: City is 'Seattle' and Forecast contains 'snow', and then join these conditions with an AND operator. This is equivalent to the following WHERE clause:
WHERE City = 'Seattle' AND Forecast LIKE '%snow%'
When Notification Services runs the subscription rule, it processes all similar conditions together, which improves performance. Notification Services then populates the rule's view with matching input and subscription pairs.
Performance Considerations
Even though Notification Services processes all similar conditions together, there is overhead when using condition actions. Notification Services must get a set of all conditions, organize the conditions for efficient evaluation, evaluate them, and then produce the resulting notifications for all subscriptions. Because of this overhead, it generally takes longer to evaluate rules that use condition actions than it takes to evaluate pre-defined actions.
Security
All condition actions execute in the context of a database user that you specify for the condition action. Using a low-privileged user minimizes the security threat in case anyone compromises your subscription management interface and inserts conditions that attempt to access other tables or perform other actions.
The database user should have restricted permissions that allow the user to only select data from event sources and to execute only user-defined functions that are used by conditions.
The SQL Server login account associated with this user must exist when Notification Services creates application objects in the application database.
Transactions
All statements in a condition action are part of the same transaction, so either they will all complete successfully or they all will be rolled back. If the transaction fails, Notification Services will write an error to the Windows application log.