Skip to main content

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
  1. Has a priority of 10 (higher than default)
  2. Will not re-trigger even if its actions modify objects (no-loop true)
  3. Fires when finding an active customer over 18 with an order over $100
  4. Applies a 10% discount to the matching order
The rule above:
  • 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
Notice how variables are bound with the $ prefix for clarity.

Writing Your First Rule

Let’s create a simple rule for a discount system:
This rule matches when:
  1. We have a customer with no previous orders (first-time customer)
  2. We have an order associated with this customer
When these conditions are met, it applies a 15% discount to the order.

Additional Resources