This issue recommends a lightweight rule engine framework – LiteFlow.
In every company’s system, there are always some systems with complex business logic that carry core business logic, and almost every requirement is related to these core businesses. These core business logic are lengthy, involving internal logical operations, caching operations, persistence operations, external resource retrieval, internal RPC calls to other systems, and so on. Over time, as the project changes hands several times, the maintenance cost will become increasingly high. Various hard code judgments and branching conditions are increasing. The abstraction of code and the decreasing reuse rate result in high coupling between modules. A small logical change will affect other modules and requires complete regression testing to verify. If you want to flexibly change the order of business processes, you need to make major code changes to abstract and rewrite methods. Real time hot change business processes are almost difficult to implement.
How to break the deadlock? LiteFlow was born for decoupling logic and orchestration. After using LiteFlow, you will find that building a low coupling, flexible system becomes effortless!
Functional characteristics
- Unified Component Definition: All logic is a component, providing a unified component implementation for all logic. Small in size, powerful.
- Lightweight rules: Based on rule files to arrange processes, learning rules only takes 5 minutes to get started, and you can understand them at a glance.
- Diversified rules: The rules support three ways of writing rule files: XML, JSON, and YML. Use whichever you like.
- Arbitrary orchestration: synchronous asynchronous mixed orchestration, even the most complex logical process, can be easily achieved using LiteFlow’s rules. You can see how the logic works by looking at the rule files.
- Rules can be loaded from anywhere: the framework provides implementations of local file configuration sources and zk configuration sources, as well as extension interfaces where you can store rules anywhere.
- Elegant hot refresh mechanism: rule changes, no need to restart your application, instantly change the rules of the application. High concurrency will not cause any confusion in the executing rules due to refreshing the rules.
- Wide support: Whether your project is built on Springboot, Spring, or any other Java framework, LiteFlow can handle it with ease.
- JDK support: Supports everything from JDK8 to JDK17. No need to worry about JDK version.
- Script language support: Script language nodes can be defined, supporting both QLExpress and Groovy scripts. More scripting languages will be supported in the future.
- Rule nesting support: As long as you can think of it, you can use simple expressions to complete complex logic orchestration with multiple nesting.
- Component retry support: Components can support retries, and each component can customize retry configurations and specify exceptions.
- Context isolation mechanism: A reliable context isolation mechanism, you don’t have to worry about data streaming in high concurrency situations.
- Declarative component support: You can make any of your classes instantly variable components.
- Detailed step information: How your link is executed, how much time each component takes, what errors are reported, it is clear at a glance.
- Stable and reliable: After more than 2 years of iteration, it runs stably on the core systems of major companies.
- Excellent performance: The framework itself consumes almost no additional performance, and performance depends on the efficiency of your component execution.
- Comes with simple monitoring: The framework comes with a command-line monitoring system that can determine the running time ranking of each component.
System Architecture
框架优势
如果你要对复杂业务逻辑进行新写或者重构,用LiteFlow最合适不过。它是一个轻量,快速的组件式规则引擎框架,组件编排,帮助解耦业务代码,让每一个业务片段都是一个组件,并支持热加载规则配置,实现即时修改。
LiteFlow利用规则表达式为驱动引擎,去驱动你定义的组件。你有想过类似以下的多线程流程编排该如何写吗?
All of this is easy with LiteFlow! The expression language learning threshold of the framework is very low, but it can complete extremely complex orchestration.
Applicable scenarios
Not applicable to which scenarios:
LiteFlow only does logic based flow, not role-based task flow. If you want to do role-based task flow, we recommend using Flowable and Activiti frameworks.
Applicable to which scenarios:
LiteFlow is suitable for businesses with complex logic, such as price engines, ordering processes, etc. These businesses often have many steps that can be broken down into independent components according to business granularity for assembly, reuse, and change. By using LiteFlow, you will get a highly flexible and scalable system. Because the components are independent of each other, it can also avoid the risk of making changes that could affect the entire system.
Springboot Scene installation and operation
Dependency:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.8.2</version>
</dependency>
to configure:
Definition of Components:
1. After relying on the above jar packages, you need to define and implement some components to ensure that SpringBoot scans these components and registers them in the context
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
2. Repeat this process and define components b and c separately
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
SpringBoot configuration file:
Then, add the configuration in your SpringBoot’s application.exe or application-Yml (using properties as an example, YAML is the same)
liteflow.rule-source=config/flow.el.xml
Definition of Rule Files:
Meanwhile, you need to define rules in config/flow.exe under resources
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(a, b, c);
</chain>
</flow>
SpringBoot automatically loads rule files at startup.
Execution:
Declaration of Startup Class:
@SpringBootApplication
//Scan the components you defined into the Spring context
@ComponentScan({"com.xxx.xxx.cmp"})
public class LiteflowExampleApplication {
public static void main(String[] args) {
SpringApplication.run(LiteflowExampleApplication.class, args);
}
}
Then you can retrieve the flowExecutor from any Spring hosted class in Springboot and perform the execution process:
@Component
public class YourClass{
@Resource
private FlowExecutor flowExecutor;
public void testConfig(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
}
}
Tips:
This DefaultContext is the default context, and users can use any of their own beans as the context to pass in. If they need to pass in their own context, they need to pass in the Class property of the user bean. Please refer to the Data Context section for details.
Example
This case is a price calculation engine designed to simulate the calculation of order prices in e-commerce.
—END—
Open source protocol:Apache2.0