Specifications

162 CHAPTER 8 Complex Event Processing with StreamInsight
Query Template Binding
The method that the CEP server uses to instantiate the query template as a standing query
depends on the development model that you use. If you are using the explicit server devel-
opment model, you create a query binder object, but you create an event stream consumer
object if you are using the implicit server development model.
The Query Binder Object
In the explicit server development model, you rst create explicit input and output adapter
objects. Next you create a query binder object as a wrapper for the query template object on
the CEP server, which in turn you bind to the input and output adapters, and then you call the
CreateQuery() method to create the standing query, as shown here:
QueryBinder myQuerybinder = new QueryBinder(myQueryTemplate);
myQuerybinder.BindProducer("querySource", myInputAdapter, inputConf,
EventShape.Point);
myQuerybinder.AddConsumer("queryResult", myOutputAdapter, outputConf,
EventShape.Point, StreamEventOrder.FullyOrdered);
Query myQuery = application.CreateQuery("query", myQuerybinder, "query description");
Rather than enqueuing CTIs in the input adapter code, you can dene the CTI behavior by
using the AdvanceTimeSettings class as an optional parameter in the BindProducer method.
For example, to send a CTI after every 10 events, set the CTI’s timestamp as the most recent
event’s timestamp, and drop any event that appears later in the stream but has an end time-
stamp earlier than the CTI, use the following code:
var ats = new AdvanceTimeSettings(10, TimeSpan.FromSeconds(0),
AdvanceTimePolicy.Drop);
queryBinder.BindProducer ("querysource", myInputAdapter, inputConf,
EventShape.Interval, ats);
The Event Stream Consumer Object
After you dene the query logic in an application that uses the implicit server development
model, you can use the output adapter factory to create an event stream consumer object.
You can pass this object directly to the CepStream.ToQuery() method without binding the
query template to the output adapter, as you can see in the following example:
Query myQuery = outputStream.ToQuery<ResultType>(typeof(MyOutputAdapterFactory),
outputConf, EventShape.Interval, StreamEventOrder.FullyOrdered);