I'm using drools to raise alarm on streaming transaction data. The drools engine is STREAM and ACTIVE mode. I also use an entry point (OM-TRANS) to transmit data to the rule engine. I have written a simple rule to test the behaviour of the engine. I got some results but i don't understand them and their are not what i expect.
This is the first simple rule:
rule "My rule"
no-loop true
when
$transaction: TransactionOmDto($msisdn: msisdn) from entry-point "OM-TRANS"
then
System.out.println("------------ an alarm on "+$msisdn+" ----------");
end
These are the results i got after testing:
------------ an alarm on msisdn_1 ----------
------------ an alarm on msisdn_1 ----------
------------ an alarm on msisdn_2 ----------
------------ an alarm on msisdn_2 ----------
------------ an alarm on msisdn_3 ----------
This is now the second version of the rule:
rule "My rule"
no-loop true
when
$transaction: TransactionOmDto($msisdn: msisdn) from entry-point "OM-TRANS"
$datasTransaction: List() from collect(TransactionOmDto(msisdn == $msisdn) from entry-point "OM-TRANS")
then
System.out.println("------------ an alarm on "+$msisdn+", total Transaction: "+$datasTransaction.size()+" ----------");
end
and i got the following results and what i expect:
------------ an alarm on msisdn_1, total Transaction: 1 ----------
(this is the one expected)
------------ an alarm on msisdn_1, total Transaction: 2 ----------
------------ an alarm on msisdn_1, total Transaction: 2 ----------
What i expected is : A sigle row ------------ an alarm on msisdn_1, total Transaction: 2 ----------
------------ an alarm on msisdn_2, total Transaction: 1 ----------
(as expected)
------------ an alarm on msisdn_2, total Transaction: 2 ----------
------------ an alarm on msisdn_2, total Transaction: 2 ----------
What i expected is : A sigle row ------------ an alarm on msisdn_2, total Transaction: 2 ----------
------------ an alarm on msisdn_3, total Transaction: 1 ----------
(this is the one expected)
------------ an alarm on msisdn_3, total Transaction: 2 ----------
------------ an alarm on msisdn_3, total Transaction: 2 ----------
What i expected is : A sigle row ------------ an alarm on msisdn_3, total Transaction: 2 ----------
------------ an alarm on msisdn_3, total Transaction: 3 ----------
------------ an alarm on msisdn_3, total Transaction: 3 ----------
------------ an alarm on msisdn_3, total Transaction: 3 ----------
What i expected is : A sigle row ------------ an alarm on msisdn_3, total Transaction: 3 ----------
Can someone explain to me why i got those result? Is it possible to get what i expect ? Thanks you.
Because your events expire only in 24h, older ones do participate in the rule logic.
Usually this can be fixed with sliding length window
over window:length(1) from entry-point "OM-TRANS"
full snippet
rule "My rule2"
no-loop true
when
$transaction: TransactionOmDto($msisdn: msisdn) over window:length(1) from entry-point "OM-TRANS"
$datasTransaction: List() from collect(TransactionOmDto(msisdn == $msisdn) from entry-point "OM-TRANS")
then
System.out.println("------------ an alarm on "+$msisdn+", total Transaction: "+$datasTransaction.size()+" ----------");
end
output
------------ an alarm on msisdn_1, total Transaction: 1 ----------
------------ an alarm on msisdn_1, total Transaction: 2 ----------
------------ an alarm on msisdn_1, total Transaction: 3 ----------