我希望在我的申请中用Siddhi替换Esper。现在esper语句是一个“超时”类型模式,我需要在独特的“名称”和“类型”(只是我可以在传入事件中查找的字符串值)的事件到达和离开时报告。我知道当事件第一次到达我的第一个窗口时事件已经到来,并且我假设如果我没有看到任何相同名称的事件并且在用户定义的超时值中键入事件,事件就会离开。这是我的esper语句的样子(请注意,在实际的esper中还有更多的内容,我为了示例而简化了这一点):
将窗口events_1.std:firstunique(name,type)创建为NameEvent
插入events_1 select * from EventCycle [events]
on pattern [every event1 = events_1->(timer:interval(4.0 sec)and not events_1(name = event1.name,type = event1.type))]从events_1中删除name = event1.name AND type = event1.type
然后我从events_1中选择irstream,并通过获取传入和删除的事件,然后从窗口获取“到达”和“已离开”事件。
对于siddhi来说,第一个唯一的窗口是相当简单的(我想?):
来自EventCycle#window.firstUnique('name')[type =='type']选择名称,在NameEvent中键入insert
但我真的在如何用Siddhi替换“模式”上的那个esper。我可以为此使用单个“from every”语句,还是需要与Siddhi采用不同的方法?
任何有助于让我走上正确道路的帮助将不胜感激!
答案 0 :(得分:0)
实现您的要求的一种方法是检查事件的不发生。 我担心,WSO2 CEP-3.1.0不支持AFAIK,非发生检查 然而,它在WSO2 CEP-4.0.0中得到了支持(我将于2015年8月24日发布,但尚未发布)。 您可以参考非出现检测样本[1]。
<强>解释强>
如果自最近的唯一事件发生以来没有发生 4秒(这是时间),我们将离开第一个事件。 所以看起来我们需要检查一个事件的不发生。
在CEP 4.0.0中,您可以按如下方式达到要求:
from EventCycle#window.firstUnique(name)[ type=='type' ]
select name, type
insert into NameEvents; -- Note: I renamed NameEvent in the question to NameEvents
-- After seeing the latest unique event (Query-A), 4 seconds later (Query-B), we're checking if no unique event has occured in between (Query-C and Query-D).
-- So, we're checking the non-occurance of an event here... See link [1] for a sample.
--Query-A
from EventCycle#window.unique(name)[ type=='type' ]
select name, type
insert into latestEvents;
-- Query-B
from latestEvents#window.time(4 seconds) -- Here, I've taken 4 seconds as the timeout.
select *
insert expired events into timedoutEvents;
-- Query-C
from every latestEvent = latestEvents[ type=='type' ] ->
keepAliveEvent = latestEvents[ latestEvent.name == keepAliveEvent.name and type=='type' ]
or timedoutEvent = timedoutEvents[ latestEvent.name == timedoutEvent.name and type=='type' ]
select latestEvent.name as name, keepAliveEvent.name as keepAliveName
insert into filteredEvents;
-- Query-D
from filteredEvents [ isNull(keepAliveName)]
select name
insert into departedLatestEvents;
-- Since we want the name from the NameEvents stream, we're joining it with the departedLatestEvents stream
from departedLatestEvents#window.length(1) as departedLatestEvent join
NameEvents#window.length(1) as NameEvent
on departedLatestEvent.name == NameEvent.name -- not checking type as both departedLatestEvents and NameEvents have events only with type 'type'
select NameEvent.name as name, 'type' as type
insert into departedFirstEvents;
代码示例中提到的链接:
1 https://docs.wso2.com/display/CEP400/Sample+0111+-+Detecting+non-occurrences+with+Patterns
希望这有帮助!