Introducing Liteflow: A Lightweight Java Rule Engine for Backend Development
This article explains the concepts, architecture, and practical usage of Liteflow, a lightweight Java rule engine that integrates with Spring Boot, supports various rule file formats, multiple component types, data contexts, and configuration options for building complex workflow processes in backend applications.
In daily development, serial or parallel business processes often lack correlation, and combining strategy and template patterns can solve this, but excessive code files become hard to manage. This article introduces Liteflow, a lightweight yet powerful rule engine that addresses these challenges from a global perspective. liteflow is a lightweight and powerful rule engine that can be used out‑of‑the‑box to quickly compose complex rule orchestrations. It supports multiple rule file formats such as XML, JSON, and YAML, and can store rule files in various back‑ends like SQL, Zookeeper, Nacos, or Apollo.
The usage of liteflow starts with obtaining a context, parsing the corresponding rule files, and executing a chain where each link contains business nodes (components) that can be written in languages like Groovy, JavaScript, Python, or Lua. The official website and Maven dependency are shown below:
# liteflow rule engine official website
https://liteflow.yomahub.com
# springboot integration liteflow
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.10.6</version>
</dependency> liteflowsupports complex flows, hot deployment, and real‑time node replacement.
Component types include:
Ordinary Component : Implement NodeComponent, used in when and then logic, with methods like process, iaAccess, isContinueOnError, and isEnd.
Switch Component : Extends NodeSwitchComponent and overrides processSwitch to decide the next node, similar to a Java switch.
Condition Component : Extends NodeIfComponent and overrides processIf to return a boolean result.
EL rule files are typically written in XML. Example snippets illustrate serial ( THEN), parallel ( WHEN), nested, switch, and conditional compositions:
# file orchestration, then = serial, when = parallel
# serial example
THEN(a, b, c, d);
# parallel example
WHEN(a, b, c);
# nested example
THEN( a, WHEN(b, c, d), e);
# switch example
SWITCH(a).to(b, c, d);
# condition example
THEN(IF(x, a), b );Data context is crucial in liteflow for passing parameters between nodes. Example execution:
# Execute flow with context
LiteflowResponse response = flowExecutor.execute2Resp("chain1", initialParams, CustomContext.class);Configuration items include rule file locations, retry counts, thread pool settings for parallel execution, request‑ID generators, and context slot sizes, as shown in the YAML snippet below:
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: trueA practical business scenario demonstrates an e‑commerce order flow where after order completion, points are granted, messages are sent, and email and SMS are dispatched in parallel:
# Example flow XML
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="test_flow">
THEN(
prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
);
</chain>
</flow>Before processing, input parameters are transformed into a context object for easy propagation. Nodes like point granting can access the context and optionally override isAccess to control execution.
In summary, most of liteflow 's work—rule parsing, component registration, and assembly—is performed at startup, resulting in high execution performance and detailed timing statistics. The article covered core concepts, component usage, EL rule syntax, configuration, and a concrete business example, with source code available on GitHub.
Project GitHub address: springboot-auth – https://github.com/thedestiny/springboot-auth/tree/main/order-server
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
