首页 > 解决方案 > 具有多次出现条件的 Siddhi 查询

问题描述

我们可以编写 Siddhi 查询,其中很少发生具有某些条件的事件,例如

对于 customerId 'xyz' 和 source 作为 'log' 的 3 个事件,我们可以使用

from every (e1 = CargoStream[e1.customerId == 'xyz' AND e1.source = 'log']<3>)

但是我们需要做的是在这三个事件之间添加条件。像所有这三个元素这样的东西应该具有相同的来源,而不是特定的值。

from every (e1 = CargoStream[e1.customerId == 'xyz' AND all these 3 events have same source does not matter the value]<3>)

我们尝试通过访问事件中的索引事件进行查询,但似乎不能很好地触发事件。

from every (e1 = CargoStream[e1.customerId == 'xyz' AND (e1[0].source == e1[1].sourse AND e1[1].source == e1[2].source)]<3>)

Siddhi Query甚至可以做到这一点吗?如果是,那么如何?

标签: complex-event-processingsiddhi

解决方案


对于您的问题,在事件中具有相同的条件。你可以使用分区

https://siddhi.io/en/v5.1/docs/query-guide/#partition

另外,调查这个问题 - https://github.com/siddhi-io/siddhi/issues/1425

查询就像 -

define stream AuthenticationStream (ip string, type string);
@purge(enable='true', interval='15 sec', idle.period='2 min') 
partition with (ip of AuthenticationStream) 
begin
   from every (e1=AuthenticationStream[type == 'FAILURE' ]<1:> -> 
        e2=AuthenticationStream[type == 'SUCCESS' ]) within  1 min 
        select e1[0].ip as ip, e1[3].ip as ip4
        having not(ip4 is null)
        insert into BreakIn 
end;

推荐阅读