Mastering Liteflow: A Lightweight Rule Engine for Spring Boot

This article introduces Liteflow, a lightweight yet powerful rule engine for Spring Boot, covering its architecture, supported rule formats, component types, EL rule file syntax, data context handling, configuration options, and a real‑world e‑commerce workflow example that demonstrates parallel and sequential processing.

Top Architect
Top Architect
Top Architect
Mastering Liteflow: A Lightweight Rule Engine for Spring Boot

1 Introduction

In daily development, serial or parallel business processes often lack correlation, and using strategy and template patterns can solve this, but many files become cumbersome. Introducing a rule engine from a global perspective addresses this issue.

2 Liteflow Rule Engine

liteflow

is a lightweight yet powerful rule engine that works out‑of‑the‑box, allowing complex rule orchestration quickly. It supports multiple rule file formats (xml, json, yaml) and storage options (SQL, Zookeeper, Nacos, Apollo, etc.).

Liteflow architecture diagram
Liteflow architecture diagram

The engine’s overall architecture is shown above. It parses rule files, registers components, and assembles information at startup for high performance.

3 How to Use Liteflow

Usage starts by obtaining a data context, parsing the corresponding rule file, and executing a chain via the flowExecutor. Each chain contains business nodes that can be written in various script languages (Groovy, JS, Python, Lua).

Dependency (Maven):

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

3.1 Components

Ordinary Component : Implement NodeComponent, override process, optionally iaAccess, isContinueOnError, isEnd.

Switch Component : Extend NodeSwitchComponent and implement processSwitch to return the next node name.

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

3.2 EL Rule Files

Rule files are typically written in XML. Examples:

# Serial composition
THEN(a, b, c, d);
# Parallel composition
WHEN(a, b, c);
# Nested composition
THEN(a, WHEN(b, c, d), e);
# Switch composition
SWITCH(a).to(b, c, d);
# Conditional composition
THEN(IF(x, a), b);

3.3 Data Context

The data context carries parameters between nodes. Execution example:

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

3.4 Parameter Configuration

Typical application.yml settings:

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

4 Business Practice

Example: In an e‑commerce scenario, after an order is completed, the flow grants points, sends messages, and concurrently sends SMS and email.

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

Images illustrate the execution flow and node processing.

Business flow example
Business flow example

5 Summary

Most of Liteflow’s work—rule parsing, component registration, and assembly—occurs at startup, giving it high execution performance and detailed timing statistics. This article introduced Liteflow’s core concepts and practical usage.

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.

rule engineworkflowLiteFlow
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

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.