Siddhi: Non-occurrence Event in Data Stream

Some behavior patterns in event stream are based on the fact that specific event hasn’t happened. has in-built mechanism to capture when some event is not happened after another. Here is the simple code example of the pattern.

The example defines an input stream with two fields. The field S of type string is the one which is important for this example. I want to capture cases when after event where S = ‘A’, there is no event with S = ‘Z’ during 5 seconds after the 1st one. At the same time there might be other events within this interval.

Important to note that if you have dependent patterns, then they need to be located in different Siddhi applications. The example below includes this aspect also.

@App:description('Description of the plan')
@sink(type = 'inMemory', topic = "_comming")
define stream comming (s1 string, a1 int, s2 string, a2 int);
define stream inp (s string, a int);

@sink(type = 'inMemory', topic = "_events")
define stream myevents (s string, a int);

@info(name = 'query3')
from inp 
select * 
insert into myevents;

@info(name = 'query1')
from every e1 = inp -> e2 = inp[e1.s=='a' and e2.s=='z'] within 5 seconds 
select e1.s as s1, e1.a as a1, e2.s as s2, e2.a as a2 
insert into _captured;

@info(name = 'query2')
from _captured#log() 
select * 
insert into comming;
@App:description("Description of the plan")
@source(type='inMemory' , topic='_comming') 
define stream comming (
    s1 string,
    a1 int,
    s2 string,
    a2 int

@source(type='inMemory' , topic='_events') 
define stream myevents (
    s string,
    a int
define stream logging (
    s string,
    a int

from myevents
select *
insert into logging;

from every e1=comming[s1=='a'] -> not myevents[s=='z'] for 5 seconds
    str:concat(e1.s1, '_?') as s,
    e1.a1 as a
insert into logging;

The event will be sent to the stream non when there is no events with ‘Z’ happened.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Post

%d bloggers like this: