Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Introduction

This sample demonstrates how to set up an execution plan to perform calculations over time by aggregating events. The queries here use time windows , and time batch windows to aggregate event over time. This sample uses uses the Event simulatorSimulator for inputs and the logger publisher for logging the outputs custom output events to the CEP consoleCustom events are events with custom mappings that does not adhere to the default event formats. For more information on event formats, see Event Formats. 

The queries used in the WindowBasedAvgTemp execution plan used in this sample is are as follows:

Code Block
-- with time sliding window of 1 mim
from TempStream#window.time(1 min)
select roomNo, avg(temp) as avgTemp
group by roomNo
insert all events into AvgRoomTempStream ;

-- with time batch (tumbling) window of 1 min
from TempStream#window.timeBatch(1 min)
select roomNo, avg(temp) as avgTemp
group by roomNo
insert all events into AvgRoomTempPerMinStream ;

...

  • Processes the events received through the TempStream.
  • When selecting the attributes, concatenate roomNo and avg(temp) renamed as avgTemp which is the average of the temperature for each room from the start. 
  • Emits those events as output events through the AvgTempFromStartStream.

Prerequisites

See Prerequisites in CEP Samples Setup page.

Building the sample

Start the WSO2 CEP server with the sample configuration numbered 0104. For instructions, see Starting sample CEP configurations. This sample configuration does the following:

  • Points the default Axis2 repo to <CEP_HOME>/sample/artifacts/0104 (by default, the Axis2 repo is <CEP_HOME>/repository/deployment/server).

Executing the sample

  1. Log into the CEP management console which is located at https://localhost:9443/carbon.

     

  2. Go to Tools -> Event Simulator. Under the 'Multiple Events' section, you can see the listed 'events.csv' file which contains some sample data. Click 'play' to start sending sample events from the file.
  3. See the output events received from the CEP console. This sample uses the logger adaptor to log output events to the console. Since this execution plan uses 1 minute time windows, observe the results for a few minutes to get all results from different queries.

    For example, given below is a screenshot of the output of the consumer sending events from the producer: