我最近将Drools集成到我的事件驱动项目中。我在那里使用以下maven工件: kie-internal , kie-api , drools-core , drools-compiler < / strong>即可。所有这些版本的版本都是 6.0.0.Beta3
这是我的代码:
try {
KnowledgeBase kbase;
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("rules.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
}
KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(EventProcessingOption.STREAM);
kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
ksession.insert(new EventA());
ksession.fireAllRules();
Thread.sleep(8000);
ksession.destroy();
} catch (InterruptedException ex) {
System.err.println(ex.getMessage());
}
规则:
declare EventA
@role( event )
end
declare EventB
@role( event )
end
rule "Timeout EventA"
salience 500
when
$a : EventA()
not(EventB(this after[0,4s] $a))
then
System.out.println("Retracting EventA: " + $a);
retract($a);
end
问题是,在我将drools依赖项更新为版本 6.0.0.CR4 (最新)之后,不会再触发超时规则...也许我会错过某些内容或者它是一个错误?< / p>
答案 0 :(得分:1)
查看“事件的内存管理”部分 http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html/DroolsComplexEventProcessingChapter.html#d0e10244
我怀疑推断的到期偏移正在收回事件,因为没有触发超时规则。