Backend Development 11 min read

Liteflow Rule Engine: Concepts, Usage, and Business Practice

This article introduces the Liteflow rule engine, explains its architecture and supported file formats, demonstrates how to configure and use it with Spring Boot, details component types and EL rule files, and showcases a practical e‑commerce workflow example with code snippets.

Top Architect
Top Architect
Top Architect
Liteflow Rule Engine: Concepts, Usage, and Business Practice

In daily development, serial or parallel business processes often lack direct correlation, and combining strategy and template patterns can solve this but leads to many files; a rule engine offers a global solution.

The liteflow engine is a lightweight yet powerful rule engine that can be used out‑of‑the‑box to orchestrate complex rules quickly. It supports multiple rule file formats (XML/JSON/YAML) and storage options (SQL, Zookeeper, Nacos, Apollo).

Typical usage starts by obtaining a data context, parsing the rule file, and executing a chain via the flow executor. Each chain consists of business nodes that can run scripts in various languages (Groovy, JS, Python, Lua). The engine’s official site is https://liteflow.yomahub.com .

<dependency>
    <groupId>com.yomahub</groupId>
    <artifactId>liteflow-spring-boot-starter</artifactId>
    <version>2.10.6</version>
</dependency>

Liteflow can express complex flows such as:

THEN(a, b, c, d);
WHEN(a, b, c);
THEN( a, WHEN(b, c, d), e);
SWITCH(a).to(b, c, d);
THEN(IF(x, a), b );

Components correspond to nodes in rule files. Three main component types are:

Ordinary Component : implements NodeComponent , used in when and then logic, with methods like 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 true/false.

EL rule files are typically written in XML. Example flow definition:

<flow>
    <chain name="test_flow">
        THEN(
            prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
        );
    </chain>
</flow>

Data context is crucial for passing parameters between nodes. Execution example:

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

Configuration can be done via YAML, for example:

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

In a business scenario, Liteflow orchestrates an e‑commerce order completion flow: granting points, sending messages, and parallel SMS/email notifications, demonstrating how to preprocess data, set up the context, and execute node logic.

Overall, most of Liteflow’s work—rule parsing, component registration, and assembly—is performed at startup, resulting in high execution performance and detailed timing statistics for each business step.

backendJavarule engineworkflowSpring BootLiteFlow
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login 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.