Rule Structure Comparison
A Drools rule consists of three main parts:- Rule Declaration: Defines the rule name and optional attributes
- Conditions (LHS): The ‘when’ section that defines what conditions must be true for the rule to fire
- Actions (RHS): The ‘then’ section that defines what actions to take when the rule fires
- Has a priority of 10 (higher than default)
- Will not re-trigger even if its actions modify objects (no-loop true)
- Fires when finding an active customer over 18 with an order over $100
- Applies a 10% discount to the matching order
- Has a priority of 10 (higher than default)
- Will not re-trigger even if its actions modify objects (no-loop true)
- Fires when finding an active customer over 18 with an order over $100
- Applies a 10% discount to the matching order
Writing Your First Rule
Let’s create a simple rule for a discount system:- We have a customer with no previous orders (first-time customer)
- We have an order associated with this customer