使用Esper,如何对事件进行动态过滤?

发布于 2024-09-20 00:04:37 字数 964 浏览 3 评论 0原文

我是在 Java 中使用 Esper 事件流引擎的新手。场景是事件作为 POJO 传入。他们有一个我想过滤的字段。过滤后的值将随时间而变化。我不希望每次发生更改时都删除并插入新语句。

示例:

事件名为“MyEvent”,并具有字段“来源”。值可以是“家庭”、“工作”或“学校”之一。 Web 服务允许用户更改他们感兴趣的“”值。 英超联赛的声明将是这样的:

select * from MyEvent where source in ( 'home', 'school' )

所以在任何时候,“学校”都可能被删除,并且必须尽快反映其影响。问题是,如何最好地实现这一目标?由于更新生效之间存在延迟,我排除了缓存的数据库调用。

想法是:

1) 拥有一个名为“SourcesOfInterest”的流,其中包含列表类型的“sources”字段,并将语句更改为:

select * from MyEvent where source in (SourcesOfInterest.win:length(1).sources)

Web 服务将“SourcesOfInterest”事件插入到此流中,其中仅查看最新的事件。 甚至不确定语法是否正确。

2) 让语句引用运行时变量。那么语句将是:

select * from MyEvent where source in ( mySourcesVariable )

Web 服务将调用

EPRuntime.setVariableValue( "mySourcesVariable", myArrayOfSources )

还有其他选项吗?其中任何一个的性能问题?

I am a novice in using the Esper event stream engine in Java. The scenario is that events are coming in as POJOs. They have a field that I want to filter on. The filtered values will change over time. I would prefer to not remove and insert a new statement every time a change occurs.

Example:

Event is named 'MyEvent', and has the field 'source'. Value could be one of 'home', 'work', or 'school'.
A web service allows users to change the values for 'source' they are interested in.
The EPL statement will look like

select * from MyEvent where source in ( 'home', 'school' )

So at any time, 'school' could be removed, and the impact must be reflected as fast as possible. The question is, how best to make this happen? I've ruled out cached database calls because of the latency between the update taking effect.

Ideas are:

1) Have a stream called 'SourcesOfInterest' with a 'sources' field of type List, and change the statement to be:

select * from MyEvent where source in (SourcesOfInterest.win:length(1).sources)

The web service inserts 'SourcesOfInterest' events into this stream, where only the most recent is looked at.
Not even sure if the syntax is right.

2) Have the statement reference a runtime variable. Then the statement would be:

select * from MyEvent where source in ( mySourcesVariable )

The web service would invoke

EPRuntime.setVariableValue( "mySourcesVariable", myArrayOfSources )

Are there other options? Performance issues to any of these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我三岁 2024-09-27 00:04:37

经过一番思考后,我使用了问题中的第二个想法。

在配置中设置该变量

在启动之前,需要使用SetmySetOfValues = new HashSet();

esperConfiguration.addVariable( mySourcesVariable, Set.class, mySetOfValues );

Web 服务按描述工作,使用 Set 而不是数组。

现在一切都很好,而且性能也不错,所以我就这么做了。

After some flailing, I used the second idea in the question.

The variable needed to be set in the configuration, prior to startup, using

Set<String> mySetOfValues = new HashSet<String>();

esperConfiguration.addVariable( mySourcesVariable, Set.class, mySetOfValues );

The web service works as described, with a Set instead of an array.

All good now, and the performance is not obscenely bad, so I'm going with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文