首页 > 解决方案 > 如何使用计时器之类的东西进行流查询?

问题描述

我正在制作一个 siddhi 应用程序。如果在特定时间没有具有相同 ID 的事件到达,我需要一个查询以从流中获取事件。

这适用于带有 WSO2 流处理器的 SiddhiApp。

假设一个 json 在时间 0s 到达

{“id”:“1566”,“状态”:“科恰班巴”}

然后另一个在 1s 有不同的 ID

{“id”:“1575”,“Departamento”:“拉巴斯”}

另一个在 4s

{“id”:“1575”,“Departamento”:“拉巴斯”}

查询应该做的是只输出第一个 1

{“id”:“1566”,“状态”:“科恰班巴”}

因为它符合条件。5 秒内只发生一个事件。另一个 1575 在那个时候有两个事件。

标签: wso2complex-event-processingsiddhi

解决方案


我找到了一种检测非发生事件的方法

https://wso2.github.io/siddhi/documentation/siddhi-4.0/#detecting-non-occurring-events

from every( s1 = SweetProductionStream) -> not SweetProductionStream[s1.id == id ] for 8 seconds
select s1.resource1 as resource
insert  into resource1;

此代码表示,在到达事件时,如果具有相同 id 的事件在 8 秒内没有到达流,它将等待,然后它将插入到 resource1 流中


推荐阅读