CEP rule language
Learn about the CEP rule language and parameters.
- An example of a CEP rule
-
"name":"This followed by that", // required; unique in tenant "createdAt": "2020-01-08T21:09:10Z", // generated; readonly "updatedAt": "2020-01-08T21:09:10Z", // generated; readonly "ruleId": "2a3ad91---xxx-xxx-xxxxxx-----xxxx-xxx, // generated; readonly "version": 1.0, // generated; readonly "status": { // generated; readonly "code": "live", "details": "Version 1.0 of this rule is live and processing." }, "instructions: { // required "dimension": [ // optional { "fieldPath": "eventDetails.businesssObject.supplierId "type": "String" } ] "pattern" : { "ifEvent": { // required "condition": { // required //Boolean expression } "repeated": { // optional "minOccurences": 3 // optional "maxOccurences": 5 // optional "consecutive": true // optional; default=false "withoutEvent": { // optional // Boolean expression } "allowCombinations": true . // optional; default=false } } "andThenEvents: [ // optional { "optional": true // optional; default=false "condition": { // required // Boolean expresssion } "shouldOccur": false // optional; default=true "consecutive": true // optional; default=false "withoutEvent": { // optional // Boolean expression } "allowCombinations": true // optional; default=false } ] "within": { // optional "timeWindow": 60 // required "fieldPath":"timestampEventOccurred" // optional } } "thenOutput": { // required "resultAlias":"" //allow mapping? "resultContext": [ // optional { "fieldPath": "eventDetails.businessObject.id } { "fieldPath": "eventDetails.businessObject.orderValue } ] } }
Where:
- dimension
- Optional partitioning of the events by a certain field., such as order ID.
"dimension": [ { "fieldPath": "eventDetails.businesssObject.suppliedId "type": "String" } ]
- pattern
- Sequence of events to detect a
pattern.
"pattern" : {
- ifEvent
- Required initial event.
"ifEvent": {
- condition
- Required condition for the initial
event.
"condition": {// Boolean expression}
- repeated
- Optional conditions on how many times the event must repeat itself. Not allowed if
andThenEvents
is specified."repeated": {
- minOccurrences
- Optional integer that specifies the minimum number of times the event occurs. Note: If no max, use timesNOrMore(n). If n=0, use oneOrMore(). If min==0 use optional().
"minOccurences": 3
- maxOccurrences
- Optional integer that specifies the maximum number of times the event occurs.Note: If min==max, use times(n,m).
"maxOccurences": 3
- consecutive
- Optional Boolean that specifies whether the event must immediately follow the preceding event or
whether another different event can occur in between. Default value is
false
.Note: If min is specified but max is not, then either awithin window
orunlessEvent
condition is required for state clearing."consecutive": true
- withoutEvent
- Optional Boolean expression that invalidates any prior matched pattern
stateOnly
valid when min/maxOccurences are specified."withoutEvent": {//Boolean expression}
- allowCombinations
- Optional Boolean. Default value is
false
. Not valid if consecutive istrue
."allowCombinations": true
} // end `repeated` } // end `ifEvent`
- andThenEvents
- Optional list of events that need to follow the initial event. Not allowed if
repeated
is provided onifEvent
."andThenEvents: [{
- optional
- Optional Boolean value that indicates whether this event is required in the sequence of events.
Default value is
false
."optional": true
- condition
- Required Boolean expression that describes the event.
- shouldOccur
- Optional Boolean value that indicates whether the event should or should not occur. Default
value is to
true
. Usefalse
to require that the event does not occur."shouldOccur": false
- consecutive
- Optional Boolean that specifies whether the event must immediately follow the preceding event or
whether another different event can occur in between. Default value is
false
."consecutive": true/false
- withoutEvent
- Optional Boolean expression that invalidates any prior matched pattern state, which means that
it stops this pattern from firing.
"withoutEvent": { //Boolean expression}
- allowCombinations
- Optional Boolean. Default value is
false
. Not valid ifconsecutive
istrue
."allowCombinations": true
} // end sample event in andThenEvents ] // end `andThenEvents` array
- within
- Optional time window within which the entire pattern from start to end must
occur.
"within": {
- timeWindow
- Required time in seconds.
"timeWindow": long
- fieldPath
- Optional path to field in the event that contains the time to use. Default value is
timestampEventRecieved
."fieldPath":"timestampEventOccurred"
} // end `within`
} // end `pattern`
- thenOutput
- Required output definition. Includes the name of the pattern that fired. Optional contextual
fields to include in output.
"thenOutput": { "resultAlias":"<name of the pattern>" //allow mapping? "resultContext": [ { "fieldPath": "eventDetails.businessObject.id } { "fieldPath": "eventDetails.businessObject.orderValue } ] } // end `thenOutput`