Question

I have very recently started working on drools. I want to create a drl file where i can choose on priority of rules to be fired. Say: Rule 1: says that the price if greater than 1000 don't buy Rule 2 : says if the price between 700 and 1000 negotiate

so if rule 1 breaks(that is the price is greater than 1000); it is pointless to go ahead with rule 2.

So could you please guide me on how to go about with such scenarios

Also, any good tutorials on Drools and how to create drool files would be of great help.

Thanks in Advance!

Was it helpful?

Solution

The following two rule definitions can be used for your use case.

rule 1
when
   $item: Item (price > 1000)
then
   modify ($item) {
       doNotBuy = true
   }

rule 2
when
   $item: Item(price>1000, price<700)
then
   modify($item) {
       negotiate = true
   }

The basic thing with the Drools is, it evaluates the when parts of your rules and decides whether then part of a rule is to be executed. You do not need to do anything except that writing meaningful conditions in the when part.

salience is a totally different beast and I recommend you to stay away from it, at least until you get familiar with drools.

OTHER TIPS

Don't try to emulate procedural behaviour in a production system by applying salience. There is no such thing as "to go ahead with [another] rule". Think of the Rule Engine evaluating all conditions simultaneously, and write your constraints so that all your rules are independent from each other.

As for books, Google will find you some, and you can also search for design patterns in production systems.

I you want to learn more about drools you could start with these 2 books:

http://www.packtpub.com/drools-developers-using-jboss-cookbook/book

http://www.packtpub.com/jboss-rules-5-x-developers-guide/book

Hope it helps,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top