WSO2 Siddhi also supports another type of patterns known as Counting Patterns. For more information, see the Siddhi Query Guide - Counting Pattern.
Let's begin by defining input streams for both the raw material supply and the sweet production.
define stream MaterialConsumptionStream(name string, user string, amount double);
define stream MaterialSupplyStream(name string, supplier string, amount double);
- The information to be output is as follows.
Name of the raw material
To generate this output, let's define an output stream as follows.
define stream ProductionDelayAlertStream(name string, amount double);
To correlate events from the consumption and supply streams, let's define a simple pattern as follows.
from every (e1=MaterialSupplyStream) -> e2=MaterialConsumptionStream within 10 min select e1.name, e1.amount insert into MaterialSupplyAlertStream;
- The above query you added does not currently contain a condition based on which the correlation is done. The condition to be added needs to consider events that have not arrived at the
MaterialSupplyStreaminput stream instead of the new events that arrive there. To do this, you can use the logical
NOToperator as a part of a logical pattern specification as shown below.
The pattern you defined here is different to the pattern defined in User Scenario 1 in the following ways.
In this scenario, you are not defining a stream reference for the
MaterialConsumptionStreamstream (i.e. similar to
e2=MaterialConsumptionStream). This is because the criterion to be met is the non-arrival of events. Therefore, you cannot check for event e2 in the non-arrival stream.
Instead of the
withinkeyword, you are using the
forkeyword. This is because the
notpattern has to be terminated either by a single
andclause (which denotes an event arriving at a different stream can terminate the clause), or a
for <time>clause (which denotes that the wait time for events not arriving is
<time>). More details, see the
notpattern in Siddhi Query Guide - Logical Patterns.
The completed Siddhi application looks as follows.