Amit Mehra
Amit Mehra

Reputation: 21

WS02 CEP Siddhi Queries

New to Siddhi CEP. Other than the regular docs on WS02 CEP can someone point to a good tutorial.

Here are our requirements. Point out some clues on the right ways of writing such queries.

Kind of execution plan required: - If device notification reports usage of Sensor 1, then monitor to see if within 5 mins if device notification reports usage of Sensor 2 also. If found then generate output stream reporting composite-activity back on REST-JSON.
- If such composite-activity is not detected during a time slot in morning, afternoon and evening then generate warning-event-stream status on REST-JSON. ( So how to find events which did not occur in time ) - If such composite-activity is not found within some time slots in morning, afternoon and evening then report failure1-event-stream status back on REST-JSON.

This should work day on day, so how will the previous processed data get deleted in WSO2 CEP.

Regards, Amit

Upvotes: 2

Views: 987

Answers (1)

Rajeev Sampath
Rajeev Sampath

Reputation: 2747

The queries can be as follows (these are draft queries and may require slight modifications to get them running)

  1. To detect sensor 1, and then sensor 2 within 5 minutes (assuming sensorStram has id, value) you can simply use a pattern like following with the 'within' keyword:

from e1=sensorStream[sensorId == '1'] -> e2=sensorStream[sensorId == '2']

select 'composite activity detected' as description, e1.value as sensor1Value, e2.value as sensor2Value

within 5 minutes

insert into compositeActivityStream;

  1. To detect non occurrences (id=1 arrives, but no id=2 within 5 minutes) we can have following two queries:

from sensorStream[sensorId == '1']#window.time(5 minutes)

select *

insert into delayedSensor1Stream for expired-events;


from e1=sensorStream[sensorId == '1'] -> nonOccurringEvent = sensorStream[sensorId == '2'] or delayedEvent=delayedSensor1Stream

select 'id=2 not found' as description, e1.value as id1Value, nonOccurringEvent.sensorId as nonOccurringId

having (not(nonOccurringId instanceof string))

insert into nonOccurrenceStream;


This will detect non-occurrences immediately at the end of 5 minutes after the arrival of id=1 event. For an explanation of the above logic, have a look at the non occurrence sample of cep 4.0.0 (the syntax is a bit different, but the same idea)

  1. Now since you need to periodically generate a report, we need another query. For convenience i assume you need a report every 6 hours (360 minutes) and use a time batch window here. Alternatively with the new CEP 4.0.0 you can use the 'Cron window' to generate this at specific times which is better for your use case.

from nonOccurrenceStream#window.timeBatch(360 minutes)

select count(id1Value) as nonOccurrenceCount

insert into nonOccurrenceReportsStream for expired-events;


You can use http input/output adaptors and do json mappings with json builders and formatters for this use case.

Upvotes: 2

Related Questions