Example

Rules

Demonstrates how helix-rules supports several rule styles in one engine. Shows Java rules, DSL rules, SpEL rules, REST rules, YAML-loaded rules, and rule filtering.
Group
Library
Path
examples/library/rules

Overview

Helix Java application that shows how to use the different rule styles supported by helix-rules.

Run this example from the shared examples build:

Run

Run this example from the shared examples build


./gradlew -p examples runExample -Pexample=library/rules --init-script "$(pwd)/helix.init.gradle"

What It Shows

  • authoring a Java rule by extending JavaRule
  • authoring a DSL-style Java rule by extending DSLRule
  • evaluating a Spring Expression Language rule with SpelRule
  • invoking an external decision endpoint with RestRule
  • loading Java and SpEL rules from YAML with YamlRulesFactory
  • filtering loaded rules with RuleFilters

Example Output

Helix rules example
java.rule=manual-review
dsl.rule=partner-west-queue
spel.rule=expedite
rest.rule=external-risk-escalate
yaml.java.rule=broker-channel
yaml.spel.rule=broker-priority
yaml.filtered.rules=yaml-priority-spel

Development

Building the Application

Run the following command to build the application:

Command

Building the Application


./gradlew clean build

Testing the Application

Run the following command to run the application tests:

Command

Testing the Application


./gradlew test
./gradlew integration

Running the Example

Run the application and inspect the rule results:

The example starts a tiny local HTTP server for the REST rule, so it does not require any external service to be running.

Command

Running the Example


./gradlew run