Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This sample demonstrates how to set up an execution plan with a pattern matching siddhi query to detect non-occurrences. In this sample we use patterns to detect non-delivered packages of a courier service within a predefined time period (for demonstration purposes we assume the time limit to deliver a package is 2 minutes here).

The query queries used in this sample is as follows. It checks whether there is a withdrawal of more than 10000, in a day where the rest of the withdrawal amounts are less than 100

The first query keeps each arrival event for 2 minutes and then emits it to overdue_deliveries_stream which is then used in the second query.

The second query uses a pattern. It looks for a pattern where, there an arrival event (through the arrivals_stream) which is followed by a delivery event (through deliveries_stream) or else an overdue delivery event (this is an arrival event which is 2 minutes old, coming through the overdue_deliveries_stream)

Now, if the pattern detects an arrival event followed by an overdue delivery event with no delivery event, that means the package is not delivered within the 2 minute time limit. 

To detect whether the delivery event is null, we use the third query isNull(deliveryId) where the deliveryId will be null if the delivery event is null.

Code Block
from arrivals_stream#window.time(2 minutes)
select *
insert expired events into overdue_deliveries_stream;


from every arrivalEvent = arrivals_stream ->
deliveryEvent = deliveries_stream[arrivalEvent.trackingId == trackingId] 
    or overdue_delivery = overdue_deliveries_stream[arrivalEvent.trackingId == trackingId]
select arrivalEvent.trackingId as trackingId, arrivalEvent.customerName as customerName, arrivalEvent.telephoneNo as telephoneNo, deliveryEvent.trackingId as deliveryId 
insert into filter_stream;


from filter_stream [ isNull(deliveryId)]  
select trackingId, customerName, telephoneNo
insert into alert_stream;  

...

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

...

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

...