流口水 - 重复事件和时间关系
一般来说,我正在为事件编写规则,这些规则等于(按属性值)事件可以在任何时间以连续方式(每秒)发生。我只想每小时触发匹配事件的规则。
更详细地说: 我想在第一次插入事件(尚不存在)时触发规则,或者在插入事件时触发规则,并且当且仅当相等的事件已插入到工作内存中,但其中最新的事件至少为一小时以前老了。
编写此类规则(将事件持续时间设为 24 小时)的合理方式是什么?
In general I am writing rules for events which equal (by attributes values) events can occur any time in consecutive manner (every second). I want to fire rules for matched events only on an hourly bases.
In more details:
I want to fire a rule when an event is inserted for the first time (not exist yet) OR when an event is inserted and if and only if equal events are already inserted to the working memory BUT the newest of them is at least one hour ago old.
What is a reasonable way of writing a rule of that kind, taking events duration will be 24H?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将“id == $e.id”替换为您用来确定两个事件彼此相关的任何约束。
Replace "id == $e.id" by whatever constraints you use to decide two events are related to each other.
您可以像这样创建一个全局队列:
您还需要从 java 访问全局队列,因此只需使用:
在此队列中保存事件和相关时间。然后每小时以java代码的形式检查这个队列,并根据时间戳执行规则。这不是糟糕的流口水方法,而是简单直接。
You could create a global queue like this:
Your also need to access your global queue from java, so just use:
In this queue save an event and related time. Then check hourly form java code this queue, and execute rules based on timestamp. This is not poor drools approach, but is straightforward.