我们有一系列事件,每个事件都具有以下属性:
public class Event {
private String id;
private String src;
private String dst;
}
此外,我们有一组我们想用EPL和Esper建模的分层或嵌套规则。当且仅当所有父规则都已被激活时才应用每个规则(所有规则都匹配实例)。例如:
2 events or more with the same src and dst in 10 seconds
+ 5 or more with src, dst the same as the src, dst in the above rule in 20s
+ 100 or more with src, dst the same as the src, dst in the above rules in 30s
我们希望检索与此规则层次结构的每个级别相对应的所有事件实例。 例如,考虑以下事件:
id ---- source -------------- destination ---------------- arrival time (second)
1 192.168.1.1 192.168.1.2 1
2 192.168.1.1 192.168.1.2 2
3 192.168.1.1 192.168.1.3 3
4 192.168.1.1 192.168.1.2 4
5 192.168.1.5 192.168.1.8 5
6 192.168.1.1 192.168.1.2 6
7 192.168.1.1 192.168.1.2 7
8 192.168.1.1 192.168.1.2 8
.....
100 other events from 192.168.1.1 to 192.168.1.2 in less than 20 seconds
我们希望我们的规则层次结构将此实例与对应于层次结构的每个级别的所有事件的id一起报告。例如,需要类似以下报告的内容:
2 or more events with src 1928.168.1.1 and dst 192.168.1.2 in 10 seconds ( Ids:1,2 )
+ 5 or more with the same src (192.168.1.1) and dst (192.168.1.2) in 20s (Ids:1,2,4,6,7)
+ 100 or more events from 192.168.1.1 to 192.168.1.2 in 30s (Ids:1,2,4,6,7,8,...)
我们如何在Esper EPL中实现这一点(检索与所有规则匹配的事件的ID)?
答案 0 :(得分:1)
复杂的用例,需要一些时间来对此进行建模。我会从保持命名窗口并使用一些匹配识别或EPL模式开始。对于规则嵌套,我建议使用insert-into触发其他语句。由触发事件启动的上下文分区也可以派上用场。对于规则之间共享的事件(如果有),例如,使用连接或子查询来反对命名窗口。对于在第一个或第二个规则的触发事件之后到达的事件,只需使用消耗触发事件的EPL语句。从简单开始构建,熟悉插入和声明重叠上下文。
答案 1 :(得分:0)
您可以将每个规则用作层次结构中下一个规则的输入,例如,规则在过去10秒内侦听匹配事件,并将结果插入'插入'子句到新流,所以下一个规则是为新的蒸汽中的事件触发等等......这是一个非常简单的用例,即使没有上下文分区也可以完成。