📘SQL database source
Starting from v2.9.0, LiteFlow supports the configuration source of standard structured databases, as long as your database is compatible with standard SQL syntax, it can be supported.
# Dependency
If you use a database as a rule configuration source, you need to add the following additional plugin dependencies:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-rule-sql</artifactId>
<version>2.9.3</version>
</dependency>
# Configuration
You do not need to configure the liteflow.ruleSource
.
liteflow:
rule-source-ext-data-map:
url: jdbc:mysql://localhost:3306/poseidon
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: 123456
applicationName: demo
#以下是chain表的配置,这个一定得有
chainTableName: chain
chainApplicationNameField: application_name
chainNameField: chain_name
elDataField: el_data
#以下是script表的配置,如果你没使用到脚本,下面可以不配置
scriptTableName: script
scriptApplicationNameField: application_name
scriptIdField: script_id
scriptNameField: script_name
scriptDataField: script_data
scriptTypeField: script_type
liteflow.rule-source-ext-data={\
"url":"jdbc:mysql://localhost:3306/poseidon",\
"driverClassName":"com.mysql.cj.jdbc.Driver",\
"username":"root",\
"password":"123456",\
"applicationName": "demo",\
"chainTableName": "chain",\
"chainApplicationNameField": "application_name",\
"chainNameField": "chain_name",\
"elDataField": "el_data",\
"scriptTableName": "script",\
"scriptApplicationNameField": "application_name",\
"scriptIdField": "script_id",\
"scriptNameField": "script_name",\
"scriptDataField": "script_data",\
"scriptTypeField": "script_type"
}
// Make sure to add code blocks to your code group
# Configuration instructions
LiteFlow does not restrict your table name and table structure, you only need to configure the table name and related field names in the parameters.
The configuration items are described as follows:
Configuration item | Description |
---|---|
url | Jdbc connection url |
driverClassName | Driver class name |
username | Database username |
password | Database password |
applicationName | Your application name |
chainTableName | The table name of the rule table |
chainApplicationNameField | Application name field name in rule table |
chainNameField | The field name of the rule name |
elDataField | Field of EL expression (only EL is stored) |
scriptTableName | The table name of your script table |
scriptApplicationNameField | Application name field name in the script table |
scriptIdField | The field name of the Id of the script component |
scriptNameField | The field name of the script component name |
scriptDataField | Field name of script data |
scriptTypeField | The field name of the script type (type refer to Define Script Component) |
In the database, you need at least one table to store the rules.
If you use scripts, you need a second table to store the scripts.
In a rule table, a row of data is a rule. In a script table, a row of data is a script component.
example:
rule table: liteflow_chain
id | application_name | chain_name | chain_desc | el_data | create_time |
---|---|---|---|---|---|
1 | demo | chain1 | test chain 1 | THEN(a, b, c, s1,s2); | 2022-09-19 19:31:00 |
script table: liteflow_script
id | application_name | script_id | script_name | script_data | script_type | create_time |
---|---|---|---|---|---|---|
1 | demo | s1 | script s1 | import cn.hutool.core.date.DateUtil def date = DateUtil.parse("2022-10-17 13:31:43") println(date) defaultContext.setData("demoDate", date) class Student { int studentID String studentName } Student student = new Student() student.studentID = 100301 student.studentName = "张三" defaultContext.setData("student",student) def a=3 def b=2 defaultContext.setData("s1",a*b) | script | 2022-09-19 19:31:00 |
2 | demo | s2 | script s2 | defaultContext.setData("s2","hello") | script | 2022-09-19 19:31:00 |
# Auto refresh
Since the structured database does not provide a monitoring mechanism, when your rules change in the database, LiteFlow cannot perceive the change. Rules are not refreshed automatically.
You need to manually call the relevant API provided by LiteFlow to complete the rule refresh. In practical applications, you can make this refresh a button or an http link on the page to operate.
For details on how to call the API to refresh the rules, please refer to Smooth hot refresh.