LiteFlow LiteFlow
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • 🍤Introduction
  • 🍓Features
  • 🍟Quick Start(Hello world)

    • 🍄Notice
    • 🌿Springboot environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌱Spring environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌵Other environment

      • 🍄Notice
      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
  • 🍢Configuration item

    • 🍄Notice
    • 🌿Springboot environment
    • 🌱Spring environment
    • 🌵Other environment
  • 🗂Rules file

    • 📔Rules file format
    • 📕Local rule file
    • 📗Zookeeper source
    • 📘SQL database source
    • 📋Nacos source
    • 🗄Etcd source
    • 📙Custom source
  • 🔗General components

    • 📎Common component
    • ✂️Switch component
    • 📌If component
    • 🧬For component
    • ⛓While component
    • 🧿Break component
  • 🧩How to write EL rules

    • 🍄Notice
    • 🌴Serial mode
    • 🎋Parallel mode
    • 🌾Switch mode
    • 🌵If mode
    • 🌳Loop mode
    • 🍁Use sub chain
    • 🍂Use sub variables
    • 💐Complex example
    • 🌻About semicolons
    • 🌰About comments
    • 🐚Component Name Package
  • 🌮Data context

    • 🍄Notice
    • 🌯Definition and use
    • 🪶Pass initialized context
  • 🛩Flow executor

    • 🍄Notice
    • 🎡Executor method
    • 🎢Chain input parameter
    • 🎈LiteflowResponse object
  • 🍋Script component

    • 🍫Choose a script language
    • 🍕Define script component
    • 🌯Define file script
    • 🍣Interact with java
    • 🍘Dynamic refresh script
  • 🍇Declarative component

    • 🥭What is a declarative component
    • 🧅Class level declaration
    • 🥥Method level declaration
  • 🎲Dynamic rules

    • 🍄Notice
    • 🎯How to build
  • 🎨Advanced features

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
    • 🥑Implicit chain
    • 🍕Private delivery
    • 🍣Component retry
    • 🍖Smooth hot refresh
    • 🍪Component aspect
    • 🍡Step information
    • 🧊Exceptions
    • 🧇Printing details
    • 🧁Custom request id
    • 🌭Multiple type rules
    • 🥗Asynchronous thread pool
    • 🍿Custom component executor
    • 🍥Simple monitor
    • 🧉DTD in Xml
  • ⛱Test cases and demo

    • 🪁Test cases
    • 🪀Demo
  • 🪂Performance
  • v2.9.X文档
  • 🍋Script component
铂赛东
2022-10-12

🍕Define script component

The script node definition is in the rule file, you need to do the following definition (for example in xml file format):

<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <nodes>
        <node id="s1" name="common script" type="script" language="groovy">
            <![CDATA[
                def a=3;
                def b=2;
                defaultContext.setData("s1",a*b);
            ]]>
        </node>

        <node id="s2" name="switch script" type="switch_script" language="groovy">
            <![CDATA[
                def count = defaultContext.getData("count");
                if(count > 100){
                    return "a";
                }else{
                    return "b";
                }
            ]]>
        </node>

        <node id="s3" name="if script" type="if_script" language="groovy">
            <![CDATA[
                return false;
            ]]>
        </node>

        <node id="s4" name="fix number loop script" type="for_script" language="groovy">
            <![CDATA[
                //This can be used to get the number of your loops, you can call the java object to get it, and the demo directly returns the number of loops
                return 10;
            ]]>
        </node>

        <node id="s5" name="条件循环脚本" type="while_script" language="groovy">
            <![CDATA[
                //It is used here to get the identifier of when to continue the loop. You can call the java object to get it. This is just a demo.
                def flag = yourJavaBean.getFlag();
                return flag;
            ]]>
        </node>

        <node id="s6" name="退出循环脚本" type="break_script" language="groovy">
            <![CDATA[
                //This is used to get the identifier of when to exit the loop. You can call the java object to get it. This is just a demo.
                def breakFlag = yourJavaBean.getFlag();
                return flag;
            ]]>
        </node>
    </nodes>

    <chain name="chain1">
        THEN(a, b, c, s1);
    </chain>

    <chain name="chain2">
        THEN(d, SWITCH(s2).to(a, b));
    </chain>

    <chain name="chain3">
        THEN(d, IF(s3, b, c));
    </chain>

    <chain name="chain4">
        FOR(s4).DO(THEN(a,b)).BREAK(s6);
    </chain>

    <chain name="chain5">
        WHILE(s5).DO(THEN(a,b));
    </chain>
</flow>

It should be noted that there are 6 types of type:

script: normal script node, no need to return in the script.

switch_script: Select the script node, the selected node ID needs to be returned in the script.

if_script: Conditional script node, the script needs to return true/false.

for_script: The number of loop nodes, the script needs to return a value, indicating the number of loops.

while_script: Conditional loop node, the script needs to return true/false, indicating what conditions will continue the loop.

break_script: Exit the loop node, the script needs to return true/false, indicating when to exit the loop.

You can write dynamic scripts to handle business logic in the place of the example.

提示

Here language is not necessary, because LiteFlow dynamically selects the scripting language according to the jar package you depend on, and uses the SPI mechanism.

The language declaration here is mainly used for the LiteFlowX plugin for syntax highlighting. If you don't add it, there will be no corresponding syntax highlighting and hinting.

Of course make sure your LiteFlowX plugin version is 1.1.1 and above.

notice

The context bean passed in the example is the default DefaultContext. If it is your custom context bean, please call the corresponding method to set and get data.

Help us improve this document (opens new window)
last update: 2022/10/24, 15:46:15
🍫Choose a script language
🌯Define file script

← 🍫Choose a script language 🌯Define file script→

Theme by Vdoing | Copyright © 2020-2022 铂赛东 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式