Setting the rank of a rule in TIBCO BusinessEvents.

Setting the rank of a rule in TIBCO BusinessEvents.

book

Article ID: KB0091147

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition -
Not Applicable -

Description

Resolution:
Description:
===========
Setting the rank of a rule in TIBCO BusinessEvents.

Environment:
==========
All Operating Systems
TIBCO BusinessEvents 4.x , 5.x

Resolution:
===========
Rule Priority and Rank.
For each RTC, the rule agenda is sorted by priority and then within priority by rank for those rules that use the same ranking mechanism. Use of priority and rank is optional. You can also use priority without using rank.TIBCO recommends that you use priority and rank features only as needed, that is, unless there is reason to set priority (or priority and rank) let the rule engine determine the sequence of execution. This lessens the complexity of rule maintenance and takes advantage of the power of the inferencing engine.

Rule Priority
Because BusinessEvents rules are declarative rather than procedural there is no inherent order for processing. However, a priority property allows you to specify the order in which rules in one RTC execute.

Rule Rank Within the Same Priority
If you want to also control the order in which rules with the same priority execute you can use the rule rank feature. The value for the Rank property is a rule function that returns a double. The larger the return value the higher the ranking. You can specify the same rule function in different rules to perform ranking across tuples of those rules.

The rank in a rule can only be assigned a value from the output of a rule function which returns a double. The scope in the rule as well the rule function returning the rank value must be same.

Scenario:

So consider the rule below CreateAccount and NewRule
-----------------------------------------------------------------------------------------------------
rule Rules.CreateAccount {
    attribute {
        priority = 5;
        forwardChain = true;
        rank = RuleFunctions.ReturnDoubleTwo;
    }
    declare {
        Events.CreateAccount request;
    }
    when {
    }
    then {
        System.debugOut("#### finished running rule CreateAccount ");
        Event.consumeEvent(request);        
    }
}

rule Rules.NewRule {
    attribute {
        priority = 5;
        forwardChain = true;
        rank = RuleFunctions.ReturnDoubleOne;
    }
    declare {
        Events.CreateAccount request;
    }
    when {
        
    }
    then {
        System.debugOut("#### finished running rule NewRule ");
        Event.consumeEvent(request);        
    }
}

the rule function RuleFunctions.ReturnDoubleTwo which returns the rank value for Rules.CreateAccount
-----------------------------------------------------------------------------------------------------
double rulefunction RuleFunctions.ReturnDoubleTwo {
    attribute {
        validity = ACTION;
    }
    scope {
        Events.CreateAccount request;
    }
    body {
        return 7;
    }
}

and the rule function RuleFunctions.ReturnDoubleOne which returns the rank value for Rules.NewRule
-----------------------------------------------------------------------------------------------------

double rulefunction RuleFunctions.ReturnDoubleOne {
    attribute {
        validity = ACTION;
    }
    scope {
        Events.CreateAccount request;
    }
    body {
        return 9;
    }
}

In the above case Rules.NewRule will be executed before Rules.CreateAccount as the rank value for Rules.NewRule is 9 which is higher(as returned by RuleFunctions.ReturnDoubleOne) than the rank value for Rules.CreateAccount which is 7 as returned by RuleFunctions.ReturnDoubleTwo .

Issue/Introduction

Setting the rank of a rule in TIBCO BusinessEvents.