Introducing LiteFlow: A Lightweight Java Rule Engine for Complex Workflow Orchestration

This article explains how the LiteFlow rule engine enables Java developers to define, configure, and execute complex serial and parallel business workflows using XML/JSON/YAML rule files, various node components, data contexts, and runtime parameters, with hot‑deployment and integration examples for Spring Boot projects.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Introducing LiteFlow: A Lightweight Java Rule Engine for Complex Workflow Orchestration

In everyday development, serial and parallel business processes often lack direct correlation, making it hard to manage them with traditional coding approaches. Combining strategy and template patterns can help, but the resulting codebase becomes fragmented. The article introduces LiteFlow, a lightweight yet powerful rule engine that solves these problems from a global perspective.

LiteFlow provides an out‑of‑the‑box solution for complex rule orchestration. It supports multiple rule file formats such as xml, json, yaml and various storage backends like sql, zk, nacos, and apollo. The engine works by obtaining a data context, parsing rule files, and executing a chain of business nodes written in languages such as Groovy, JavaScript, Python, or Lua.

Typical Maven dependency for Spring Boot integration:

# liteflow rule engine official site
https://liteflow.yomahub.com
# springboot integration liteflow
<dependency>
    <groupId>com.yomahub</groupId>
    <artifactId>liteflow-spring-boot-starter</artifactId>
    <version>2.10.6</version>
</dependency>

LiteFlow can model complex flows, including hot‑deployment that allows real‑time node replacement or addition after rule files are modified.

Component Types

Ordinary Component : Implement NodeComponent, used in when and then logic. Override isContinueOnError to decide error handling and isEnd to terminate the flow.

Switch Component : Extend NodeSwitchComponent and implement processWitch to choose the next node, similar to a Java switch.

If Component : Extend NodeIfComponent and override processIf to return a boolean result.

Example of a switch component expression:

# flow rule expression – switch component
SWITCH(a).to(b, c);
# processWitch must return "b" or "c" to trigger the corresponding logic
# flow rule expression – condition component
IF(x, a, b);

EL Rule Files

Rule files are typically written in XML. The following snippets illustrate serial ( THEN), parallel ( WHEN), nested, switch, and conditional compositions:

# file orchestration, THEN for serial, WHEN for parallel
# serial example
THEN(a, b, c, d);
# parallel example
WHEN(a, b, c);
# nested serial & parallel
THEN( a, WHEN(b, c, d), e);
# switch example
SWITCH(a).to(b, c, d);
# condition example
THEN(IF(x, a), b );

Data Context

The data context carries parameters between nodes. Execution typically looks like:

LiteflowResponse response = flowExecutor.execute2Resp("chain1", initialParams, CustomContext.class);

Parameters are usually set in the first node and then accessed throughout the flow.

Parameter Configuration

Key configuration items include rule file location, retry count (leveraging spring-retry), thread pool settings for parallel execution, request‑ID generator, and context slot size. Example YAML snippet:

liteflow:
  ruleSource: liteflow/*.el.xml
  retry-count: 0
  print-execution-log: true
  monitor:
    enable-log: true
    period: 300000
  request-id-generator-class: com.platform.orderserver.config.AppRequestIdGenerator
  slot-size: 10240
  main-executor-works: 64
  when-max-wait-seconds: 15
  when-max-workers: 16
  when-queue-limit: 5120
  parse-on-start: true
  enable: true

Business Practice Example

A typical e‑commerce scenario demonstrates order completion triggering points, score granting, message queue publishing, and parallel email/SMS sending:

# main flow for e‑commerce order processing
<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <chain name="test_flow">
        THEN(
            prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
        );
    </chain>
</flow>

Before executing business logic, input parameters are transformed into a custom context object to simplify data passing.

Each business step (e.g., granting points) is encapsulated as a node component stored in test_flow.el.xml. The article notes that more complex scenarios may require a full workflow engine rather than LiteFlow.

Conclusion

Most of LiteFlow's work—rule parsing, component registration, and assembly—occurs at startup, delivering high execution performance and detailed timing/statistics for each business step. The source code is available on GitHub for further exploration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Javarule engineBackend DevelopmentSpring BootLiteFlow
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.