[rules-users] Why does it seem like salience is being ignored?

Ladd ladd at codemettle.com
Fri Jul 13 13:37:51 EDT 2012


I'm using drools-camel 5.4.0.Final.  ksession is stateful, I'm in STREAM
mode, and rules are fired with fireUntilHalt().

My test route is:

from( "direct:test-message" ).to(
"drools://node/ksession1?action=insertMessage" );

I'm sending my objects into the engine like so:

template.sendBody( "direct:test-message", new Person( "Bob" ) );
template.sendBody( "direct:test-message", new Person( "Jim" ) );

I have two rules that I'd like to fire in a specific order (1a followed by
1b).

If I define rule1a first in my drl it fires first as I would expect (with or
without a salience specified).  But if I define rule1b first, that fires
first even though rule1a has a higher salience.

Here are my two rules / test cases and the results:

*Scenario 1 (rule1a first first as I want it to):*

rule += "rule rule1a salience 100 \n";
rule += "  when \n";
rule += "    $m : Message( body.class == Person.class, $body : body ) \n";
rule += "    $p : Person() from $body \n";
rule += "  then \n";
rule += "    System.err.println( \"rule1a: Just found person \" +
$p.getName() ); \n";
rule += "end\n";
        
rule += "rule rule1b\n";
rule += "  when \n";
rule += "    $m : Message() \n";
rule += "  then \n";
rule += "    System.err.println( \"rule1b: Just found message \" +
$m.getBody().toString() ); \n";
rule += "end\n";

*Output:*
rule1a: Just found person Bob
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person at b49448
rule1a: Just found person Jim
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person at f4e9d3

*Scenario 2 (rule1b fires first even through rule1a has a higher salience):*

rule += "rule rule1b\n";
rule += "  when \n";
rule += "    $m : Message() \n";
rule += "  then \n";
rule += "    System.err.println( \"rule1b: Just found message \" +
$m.getBody().toString() ); \n";
rule += "end\n";
        
rule += "rule rule1a salience 100 \n";
rule += "  when \n";
rule += "    $m : Message( body.class == Person.class, $body : body ) \n";
rule += "    $p : Person() from $body \n";
rule += "  then \n";
rule += "    System.err.println( \"rule1a: Just found person \" +
$p.getName() ); \n";
rule += "end\n";

*Output:*
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person at 1133fd6
rule1a: Just found person Bob
rule1b: Just found message
org.apache.camel.component.bean.pojomessage.Person at ca425c
rule1a: Just found person Jim

Something simple I'm sure.  Any pointers to get my salience working?

Thanks for taking the time to help me out!!

- Ladd

--
View this message in context: http://drools.46999.n3.nabble.com/Why-does-it-seem-like-salience-is-being-ignored-tp4018669.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list