LiteFlow LiteFlow
💒首页
  • v2.13.2(当前版本)
  • What's New

    • 🌈What' s New In LiteFlow v2.13.2?
  • 历史版本

    • v2.12.X
    • v2.11.X
    • v2.10.X
    • v2.9.X
    • v2.8.X
  • 升级指南

    • 🌈2.13.0升级指南
    • 2.12.4升级指南
    • 2.12.0升级指南
    • 升级到2.9.3说明
    • 升级到2.9.X说明
    • 升级到2.8.X说明
    • 升级到2.7.X说明
👑LF CLUB社区
  • 常见问题
  • 专题解释

    • 如何理解上下文这个概念?
    • Slot是一个什么样的概念,在框架中起到什么样的作用?
💖赞助
🧩插件
🔥PPT
  • 项目介绍
  • 项目成员
  • 更新记录
  • 参与开发
👥加入群聊
🧤谁在使用
  • Gitee (opens new window)
  • GitCode (opens new window)
  • Github (opens new window)

广告采用随机轮播方式显示 ❤️成为赞助商
💒首页
  • v2.13.2(当前版本)
  • What's New

    • 🌈What' s New In LiteFlow v2.13.2?
  • 历史版本

    • v2.12.X
    • v2.11.X
    • v2.10.X
    • v2.9.X
    • v2.8.X
  • 升级指南

    • 🌈2.13.0升级指南
    • 2.12.4升级指南
    • 2.12.0升级指南
    • 升级到2.9.3说明
    • 升级到2.9.X说明
    • 升级到2.8.X说明
    • 升级到2.7.X说明
👑LF CLUB社区
  • 常见问题
  • 专题解释

    • 如何理解上下文这个概念?
    • Slot是一个什么样的概念,在框架中起到什么样的作用?
💖赞助
🧩插件
🔥PPT
  • 项目介绍
  • 项目成员
  • 更新记录
  • 参与开发
👥加入群聊
🧤谁在使用
  • Gitee (opens new window)
  • GitCode (opens new window)
  • Github (opens new window)
  • 🍤LiteFlow简介
  • 🍓项目特性
  • 🧁环境支持

  • 🍟快速开始(Hello world)

  • 🍢配置项

  • 🗂规则文件

    • 📔规则文件格式
    • 📕本地规则文件配置
    • 📗ZK规则文件配置源
    • 📘SQL数据库配置源
      • 依赖
      • 配置
      • 配置说明
      • 使用你项目中的dataSource来进行连接
      • 轮询自动刷新
      • 小例子
    • 📋Nacos配置源
    • 🗄Etcd配置源
    • 📜Apollo配置源
    • 📑Redis配置源

    • 📙自定义配置源
  • 🔗常规组件

  • 🧩EL规则的写法

  • 🌮数据上下文

  • 🛩执行器

  • 🍋脚本组件

  • 🍇声明式组件

  • 🎲用代码动态构造规则

  • 🎨高级特性

  • ⛱测试用例以及示例

  • 🪂性能表现
  • v2.11.X文档
  • 🗂规则文件
铂赛东
2022-10-06
目录

📘SQL数据库配置源

LiteFlow从v2.9.0开始,原生支持了标准关系型结构化数据库的配置源,只要你的数据库兼容标准SQL语法,都可以支持。

# 依赖

如果使用数据库作为规则配置源,你需要添加以下额外插件依赖:

<dependency>
    <groupId>com.yomahub</groupId>
    <artifactId>liteflow-rule-sql</artifactId>
    <version>2.11.4.2</version>
</dependency>

# 配置

依赖了插件包之后,你无需再配置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
        #是否开启SQL日志
        sqlLogEnabled: true
        #是否开启SQL数据轮询自动刷新机制 默认不开启
        pollingEnabled: true
        pollingIntervalSeconds: 60
        pollingStartSeconds: 60
        #以下是chain表的配置,这个一定得有
        chainTableName: chain
        chainApplicationNameField: application_name
        chainNameField: chain_name
        elDataField: el_data
        chainEnableField: enable
        #以下是script表的配置,如果你没使用到脚本,下面可以不配置
        scriptTableName: script
        scriptApplicationNameField: application_name
        scriptIdField: script_id
        scriptNameField: script_name
        scriptDataField: script_data
        scriptTypeField: script_type
        scriptLanguageField: script_language
        scriptEnableField: enable
    
    liteflow.rule-source-ext-data={\
      "url":"jdbc:mysql://localhost:3306/poseidon",\
      "driverClassName":"com.mysql.cj.jdbc.Driver",\
      "username":"root",\
      "password":"123456",\
      "applicationName": "demo",\
      "sqlLogEnabled": true,\
      "pollingEnabled": true,\
      "pollingIntervalSeconds": 60,\
      "pollingStartSeconds": 60,\
      "chainTableName": "chain",\
      "chainApplicationNameField": "application_name",\
      "chainNameField": "chain_name",\
      "elDataField": "el_data",\
      "chainEnableField": "enable",\
      "scriptTableName": "script",\
      "scriptApplicationNameField": "application_name",\
      "scriptIdField": "script_id",\
      "scriptNameField": "script_name",\
      "scriptDataField": "script_data",\
      "scriptTypeField": "script_type",\
      "scriptLanguageField": "script_language",\
      "scriptEnableField": "enable"
      }
    
    // Make sure to add code blocks to your code group

    # 配置说明

    LiteFlow并不约束你的表名和表结构,你只需要把表名和相关的字段名配置在参数里即可。

    对于配置项说明如下:

    配置项 说明
    url jdbc的连接url
    driverClassName 驱动器类名
    username 数据库用户名
    password 数据库密码
    applicationName 你的应用名称
    sqlLogEnabled 是否开启SQL日志 默认开启
    pollingEnabled 是否开启SQL数据轮询自动刷新机制 默认不开启
    pollingIntervalSeconds SQL数据轮询时间间隔(s) 默认为60s
    pollingStartSeconds 规则配置后首次轮询的起始时间(s) 默认为60s
    chainTableName 编排规则表的表名
    chainApplicationNameField 编排规则表中应用名称存储字段名
    chainNameField 规则名称存储的字段名
    elDataField EL表达式的字段(只存EL)
    chainEnableField 此chain是否生效,此字段最好在mysql中定义成tinyInt类型
    scriptTableName 你的脚本存储表的表名
    scriptApplicationNameField 脚本表中应用名称存储字段名
    scriptIdField 脚本组件的Id的字段名
    scriptNameField 脚本组件名称的字段名
    scriptDataField 脚本数据的字段名
    scriptTypeField 脚本类型的字段名(类型参照定义脚本组件)
    scriptLanguageField 脚本语言类型(groovy | qlexpress | js | python | lua | aviator | java)
    scriptEnableField 此脚本是否生效,此字段最好在mysql中定义成tinyInt类型

    在数据库中,你至少需要一张表来存储编排规则,这是必须的。

    如果你使用到了脚本,那么需要第二张表来存储脚本。

    在规则表中,一行数据就是一个规则。在脚本表中,一行数据就是一个脚本组件。


    举例:

    规则表:liteflow_chain

    id application_name chain_name chain_desc el_data create_time
    1 demo chain1 测试流程1 THEN(a, b, c, s1,s2); 2022-09-19 19:31:00

    脚本表:liteflow_script

    id application_name script_id script_name script_data script_type script_language create_time
    1 demo s1 脚本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 groovy 2022-09-19 19:31:00
    2 demo s2 脚本s2 defaultContext.setData("s2","hello") script groovy 2022-09-19 19:31:00

    # 使用你项目中的dataSource来进行连接

    LiteFlow从v2.10.6开始支持了使用项目中已存在的Datasource来进行数据库连接。如果你项目中已有链接配置,比如:

    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/poseidon
    spring.datasource.username=root
    spring.datasource.password=123456
    

    那么你在rule-source-ext-data-map中无需再配置以下几项:

    url: jdbc:mysql://localhost:3306/poseidon
    driverClassName: com.mysql.cj.jdbc.Driver
    username: root
    password: 123456
    

    提示

    需要注意的是,如果你的系统中声明了多个数据源,那么LiteFlow会自动判断该选用哪个数据源。

    如果你的系统中使用了动态数据源,那么请确保默认数据源是含有LiteFlow链路数据的表数据的。

    # 轮询自动刷新

    LiteFlow从v2.11.1开始,支持SQL数据源轮询模式的自动刷新机制。你可以在配置项中通过pollingEnabled: true来开启自动刷新:

      liteflow:
        rule-source-ext-data-map:
          ...
          pollingEnabled: true
          ##以下非必须,默认1分钟
          pollingIntervalSeconds: 60
          pollingStartSeconds: 60
          ...
      
      liteflow.rule-source-ext-data={\
        ...\
        "pollingEnabled": true,\
        "pollingIntervalSeconds": 60,\
        "pollingStartSeconds": 60,\
        ...
        }
      
      // Make sure to add code blocks to your code group

      轮询模式的自动刷新根据预设的时间间隔定时拉取SQL中的数据,与本地保存的数据SHA值进行对比来判断是否需要更新数据。

      定时轮询存在些微的性能消耗;受轮询间隔限制,数据更新有一定延迟性。

      # 小例子

      为了让大家能简单上手SQL规则文件的配置和运行,这里有一个小demo,大家可以拉到本地来运行,需要你替换数据库的配置信息。

      运行项目前,先读项目里的readme.txt文件。

      https://github.com/bryan31/liteflow-ext-rule-demo

      帮助我们改善此文档 (opens new window)
      上次更新: 2024/04/09, 18:39:17
      📗ZK规则文件配置源
      📋Nacos配置源

      ← 📗ZK规则文件配置源 📋Nacos配置源→

      Theme by Vdoing | Copyright © 2020-2025 铂赛东 | MIT License
      沪ICP备18012955号-2
      • 跟随系统
      • 浅色模式
      • 深色模式
      • 阅读模式