Introduction
This sample demonstrates how to set up an execution plan with triggers. This sample uses the Event simulator for inputs and the logger publisher for logging the outputs to the CEP console.
The execution plan used in this sample is as follows.
The following query triggers an event in the
periodicalTriggerStream
event stream every 5 seconds. The purpose of this trigger is to generate events in theperiodicalTriggerStream
event stream in order to merge it with thesensorStream
event stream.define trigger periodicalTriggerStream at every 5 sec ;
The following query forwards a processed event as an output to the
cronTriggerStream
every 10 seconds.define trigger cronTriggerStream at '*/10 * * * * ?' ;
The following query merges the
periodicalTriggerStream
andsensorStream
event streams. Only the values of the attributes specified in the query are merged. Attribute values are taken from thesensorStream
event stream and inserted into theperiodicalTriggerStream
event stream.from periodicalTriggerStream join sensorStream#window.time(10 sec) select meta_timestamp, meta_isPowerSaverEnabled, meta_sensorId, meta_sensorName, correlation_longitude, correlation_latitude, triggered_time, humidity, sensorValue insert into periodicalTriggeredSensorStream;
The following query merges the
cronTriggerStream
andsensorStream
event streams. Only the values of the attributes specified in the query are merged. Attribute values are taken from thesensorStream
event stream and inserted into thecronTrigerredSensorStream
event stream.from cronTriggerStream join sensorStream#window.time(10 sec) select meta_timestamp, meta_isPowerSaverEnabled, meta_sensorId, meta_sensorName, correlation_longitude, correlation_latitude, triggered_time, humidity, sensorValue insert into cronTriggeredSensorStream;
Prerequisites
See Prerequisites in the CEP Samples Setup page.
Building the sample
Start the WSO2 CEP server with the sample configuration numbered 0119. For instructions, see Starting sample CEP configurations. This sample configuration does the following:
- Creates the following event streams.
org.wso2.event.sensor.stream:1.0.0
periodicalTriggeredSensorStream:1.0.0
cronTriggeredSensorStream:1.0.0
- Creates an execution plan named
ExecutionPlan
. - Creates the following event publishers.
periodicalTriggeredSensorStreamLogger
cronTriggeredSensorStreamLogger
Executing the sample
Follow the steps below to execute the sample.
- Log into the CEP Management Console.
Click on the Tools tab and then click Event Simulator to open the Event Stream Simulator page. A file named
events.csv
containing sample data is displayed in the Send multiple events section as follows. Click Play to start sending events to the CEP from this file.
As a result, the following output is displayed in the CLI.[2016-02-09 15:14:20,005] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: cron, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:false, meta_sensorId:100, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011060002, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:23,399] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:false, meta_sensorId:100, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011063398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:23,399] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:true, meta_sensorId:101, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011063398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:23,400] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:false, meta_sensorId:103, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011063398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:23,400] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:true, meta_sensorId:104, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011063398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:28,399] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:false, meta_sensorId:100, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011068398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:28,399] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:true, meta_sensorId:101, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011068398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:28,399] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:false, meta_sensorId:103, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011068398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:28,400] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: periodical, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:true, meta_sensorId:104, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011068398, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:30,004] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: cron, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:true, meta_sensorId:101, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011070003, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:30,004] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: cron, Event: meta_timestamp:199008131245, meta_isPowerSaverEnabled:false, meta_sensorId:103, meta_sensorName:temperature, correlation_longitude:23.45656, correlation_latitude:7.12324, triggered_time:1455011070003, humidity:100.34, sensorValue:23.4545 [2016-02-09 15:14:30,004] INFO {org.wso2.carbon.event.output.adapter.logger.LoggerEventAdapter} - Unique ID: cron, Event: