Search code examples
eventssequencedroolscomplex-event-processing

Looking for an example of drools bassd rule for sequence of events


I tried a few different formats but I'm interested in finding matches for when event of A follows B and the next set within the sequence doesn't begin until the previous sequence ends


Solution

  • A rule like

    rule x1
    when
      $e1 : Event( eventCode == "NMG_ESO 15", text contains "Exception Time")
      $e2 : Event( this after $e1,
                   eventCode == "NMG_DET 57", text contains "Exception Time")
    then ... end
    

    fires when the first NMG_DET 57 arrives after the NMG_ESO 15. It would also fire for the next NMG_DET 57. It is now up to you to provide more precise requirements and handle the first match accordingly. Perhaps you'll have to retract $31and $e2 so that the engine is ready to detect another pair, or maybe not.

    You can extend this easily to a succession of three events. Again, after the first match you'll have to decide what should happen.