SQL Server 2008 R2 - StreamInsight - Event Payloads
One of the key decisions you’ll make when working with StreamInsight is the payload that will be carried by each event. Events contain and EventKind (which is related to whether they’re inserting a new event or modifying an existing one), some temporal information (depending upon the EventShape -> Point, Interval or Edge) and a payload that is user-defined.
A payload is defined via a .NET class or struct. In general, a class will be a better option as it ensures field ordering which is likely to be important for generic (vs typed) adapters. StreamInsight ignores anything except public fields and properties and there are limitations on the data types. For example, basic .NET types are permitted but not any of the nested types.
A payload will typically look like:
public class TollPayload
{
public int TollBoothID { get**;** set**; }**
public int LaneID { get**;** set**; }**
public int VehicleType { get**;** set**; }**
public String TagID { get**;** set**; }**
}
In addition to the fields and properties, I’d suggest a few other items are helpful.
First, make sure you override the ToString() method. It’s helpful to be able to just show the contents of an event as a string without needing to couple the consumer’s code to the payload fields. This is particularly useful with logging.
Second, I find it useful to provide public static methods that convert types (or enums) to much more meaningful names. In particular, this can be useful while projecting the event fields in the LINQ standing queries.
2010-01-16