简体   繁体   English

Drools 5.1.1意外的累积和收集行为

[英]Drools 5.1.1 unexpected Accumulate and Collect behavior

I'm using Spring AMQP to read messages from RabbitMQ. 我正在使用Spring AMQP从RabbitMQ中读取消息。 After a message is read it's deserialized into one header (parent) object and multiple detail (child) objects. 读取消息后,将其反序列化为一个标头(父)对象和多个详细信息(子对象)对象。 Those facts are then inserted into a Drools stateless rule session. 然后将这些事实插入Drools无状态规则会话中。 Finally, the updated facts are inserted into a database. 最后,将更新后的事实插入数据库中。

I have several rules that will aggregate the detail facts using either the collect or accumulate functions. 我有一些规则,这些规则将使用collect或累加函数汇总详细事实。 Here's an example. 这是一个例子。

rule "Header.TotalDuration" 
when 
    h : BresHeader() 
    n : Number() 
            from accumulate( d : BresDetail(willSendToInvoice==true, 
                                            uniqueConfID ==   h.uniqueConfID),
                             sum(d.Duration) ) 
then 
    h.TotalDuration = new Integer(n.longValue()); 
    System.out.println("[TotalDuration] rule ran"); 
end 

If I run this once (reading in one message) in jUnit, the TotalDuration is calculated correctly. 如果我在jUnit中运行一次(读入一条消息),则TotalDuration计算正确。 If I run it in tomcat (continuously reading messages) the values for TotalDuration are not correct and increase after each each pass (message is grabbed, rules ran, facts persisted, repeat) and I can't figure out why. 如果我在tomcat中运行它(连续读取消息),则TotalDuration的值不正确,并且每次通过后都会增加(捕获消息,运行规则,事实仍然存在,重复),但我不知道为什么。

Can anyone shed light on this behavior? 谁能阐明这种行为?

也许您有一个static变量,可以将事实从以前的消息继续传递到新消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM