This sample demonstrates how to set up an execution plan with a sequence-based query that can be used to detect trends from a stock trades stream. This sample uses the Event Simulator for inputs and the logger publisher for logging the outputs to the DAS console.
The query used in this sample is as follows:
- Processes the events received through the
- First it looks for an event
e1with the condition where the price is greater than 20.
- Then it looks for one or more events,
e2with a condition:
((e2[last].price is null) and price>=e1.price)is used to check the first event after
(e2[last].price is null)returns true since there is no last event in
e2. Then it checks for the condition where the current event price is greater than
((not (e2[last].price is null)) and price>=e2[last].price)this part is for any subsequent events. In this case the last of e2 is not null, and we check whether the price of the current event is greater than the last event. i.e. we are looking for one or more events with a continuous price increase from this whole condition.
- Then we look for another event with a price drop from the last
e2event from the condition
- From the select clause we select the attributes
e3.price as priceAfterPeak.
- Finally the event is output to the
Set up the prerequisites required for all samples.
Building the sample
Start the WSO2 DAS server with the sample configuration numbered 0109. For instructions, see Starting sample CEP configurations.
This sample configuration points the default Axis2 repo to
<DAS_HOME>/samples/cep/artifacts/0109 (by default, the Axis2 repo is
Executing the sample
Log into the DAS Management Console.
- Go to Tools -> Event Simulator. Under the Multiple Events section, the
events.csvfile is listed. This file contains some sample data. Click Play to start sending sample events from the file.
View the output events received from the DAS console. This sample uses the logger adaptor to log output events to the console.
The following is an example screenshot of the output of the consumer sending events from the producer: