All docs This doc

Versions Compared

Key

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

...

Info

WSO2 Siddhi also supports another type of patterns known as Counting Patterns. For more information, see the Siddhi Query Guide - Counting Pattern.

Tip
titleBefore you begin:

Try Correlating Simple Events.

...

  1. Let's begin by defining input streams for both the raw material supply and the sweet production.

    Panel
    define stream MaterialConsumptionStream(name string, user string, amount double);
    Panel
    define stream MaterialSupplyStream(name string, supplier string, amount double);
  2. The information to be output is as follows.
    • Name of the raw material

    • Production amount

    To generate this output, let's define an output stream as follows. 

    Panel
    define stream ProductionDelayAlertStream(name string, amount double);
  3. To correlate events from the consumption and supply streams, let's define a simple pattern as follows.

    Panel
    from every (e1=MaterialSupplyStream) -> e2=MaterialConsumptionStream
    	within 10 min
    select e1.name, e1.amount
    insert into MaterialSupplyAlertStream;
  4. 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 

    MaterialSupplyStream input stream instead of the new events that arrive there. To do this, you can use the logical NOT operator as a part of a logical pattern specification as shown below.

    Panel

    from every (e1=MaterialSupplyStream) -> not MaterialConsumptionStream[name == e1.name and amount == e1.amount]
    for 15 min
    select e1.name, e1.amount
    insert into MaterialSupplyAlertStream;

    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 MaterialConsumptionStream stream (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 within keyword, you are using the for keyword. This is because the not pattern has to be terminated either by a single and clause (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 not pattern in  Siddhi Query Guide - Logical Patterns.

The completed Siddhi application looks as follows.

...