Wso2 如何使用siddhi从事件流中获取最后一个事件

Wso2 如何使用siddhi从事件流中获取最后一个事件,wso2,complex-event-processing,siddhi,Wso2,Complex Event Processing,Siddhi,我有两个事件流:source和dest 资料来源: { "name":"src.testevent", "version": "0.0.1", "description": "source test event stream", "metaData":[{"name":"id","type":"INT"}], "correlationData":[], "payloadData":[] } 目的地: { "name":"sink.testevent", "version": "0.0.

我有两个事件流:source和dest

资料来源:

{
"name":"src.testevent",
"version": "0.0.1",
"description": "source test event stream",
"metaData":[{"name":"id","type":"INT"}], 
"correlationData":[],   
"payloadData":[]
}
目的地:

{
"name":"sink.testevent",
"version": "0.0.1",
"description": "sink test event stream",
"metaData":[{"name":"id","type":"int"}], 
"correlationData":[],   
"payloadData":[{"name":"Severity","type":"INT"}]
}
执行计划如下:

<?xml version="1.0" encoding="UTF-8"?>
<executionPlan name="testexecplan"
 statistics="disable" trace="enable"
 xmlns="http://wso2.org/carbon/eventprocessor">

  <description>Execution plan for testing</description>
  <siddhiConfiguration>
    <property name="siddhi.enable.distributed.processing">false</property>
    <property name="siddhi.persistence.snapshot.time.interval.minutes">0</property>
  </siddhiConfiguration>
  <importedStreams>
    <stream as="srcstream" name="src.testevent" version="0.0.1"/>
  </importedStreams>
  <queryExpressions><![CDATA[

// Create temporary stream
define stream tmpstream (id int, Severity int);

// Create some events at tmpstream
from srcstream as a
select a.meta_id as id, 0 as Severity
insert into tmpstream;

from srcstream as a
select a.meta_id as id, 1 as Severity
insert into tmpstream;

from srcstream as a
select a.meta_id as id, 2 as Severity
insert into tmpstream;

// Move last event from temporary stream to sink stream
from tmpstream#window.Length(1) as a
select a.id as meta_id, a.Severity
insert into sinkstream;

]]></queryExpressions>
  <exportedStreams>
    <stream name="sink.testevent" valueOf="sinkstream" version="0.0.1"/>
  </exportedStreams>
</executionPlan>
即处理后的三个事件

我做错了什么


提前感谢您的回复。

长度窗口只会保留指定的最新事件数,并使旧事件过期。在您的情况下,由于窗口大小为1,它将保留最后一个事件,并使其他事件过期

我认为您需要的是输出速率限制[1],它可以根据时间或长度输出窗口的最后一个事件。类似下面的查询而不是上一个查询可能适合您

from tmpstream 
select id, Severity 
output last every 3 events
insert into sinkstream;

如果tmp eventstream中的事件少于三个(例如:从srcstream[meta_id==9999]作为一个…),则sink eventstream根本没有事件。这不是我需要的。嗨,我想这取决于你如何定义最后一个事件。由于这些是流,您需要定义您是否需要考虑流的最后5分钟或流的最后N个事件或类似事件的最后一个事件。您能否解释一下您需要最后一个事件的内容(即基于时间的、基于事件的)?我需要流中没有时间条件的最后一个(在本例中是一个)事件。临时流可以包含任意数量的事件。获取事件流的最新版本很重要(我需要流的最后N个事件)。嗨,流本身是一个连续的事件流,没有最后一个事件的概念。要获取最后一个事件,需要使用流上的窗口。考虑使用长度为1的窗口的查询。假设它将首先收到严重性为2的事件。此时,这是最后一个事件,将被放到窗口中。当严重性为1的事件到达时,这将是最后一个事件,依此类推。因此,您将无法提取最后一个事件,除非它与已定义的某种窗口有关。
from tmpstream 
select id, Severity 
output last every 3 events
insert into sinkstream;