Search code examples
javadroolscomplex-event-processing

How to select 2 different attributes from an event in Drools


I am trying to write a drools rule that check if two events happens from the same stream. I have a compliance rules class which contains logic (in the working memory) to be compared with events coming from entry point. all I need is to detect the occurrence of two events, for example I want to detect that event A occurred and after that B occurred. I wrote this role in drools syntax

$comrule : Comprules ( pattern == "response" , isBefore == false)  
Event  (task == $comrule.antecedent) from entry-point StoreOne  
Event (task == $comrule.consequent) from entry-point StoreOne

the problem is this technique doesn't work. the only one working is when I wrote this

Event  (task == $comrule.antecedent) from entry-point StoreOne  
not Event (task == $comrule.consequent) from entry-point StoreOne

I read the drools documentation but I couldn't find any solve to this problem any help will be appreciated


Solution

  • The typical pattern for checking that two Events occur in the right order is this:

    Comprules( pattern == "response", !isBefore, $a: antecedent, $b: consequent )
    $one: Event( task == $a ) from entry-point StoreOne  
    $two: Event( task == $b, this after $one ) from entry-point StoreOne
    

    Using not tests for the absence of a fact, which would be the situation after $one has arrived while $two still is absent.