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
      • Complex example(1)
      • Complex example(2)
      • Summarize
    • 🌻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文档
  • 🧩How to write EL rules
铂赛东
2022-06-29
Contents

💐Complex example

After the above few chapters, do you have a general understanding of how to write EL rules?

In this chapter, we combine the above chapters to see two examples of complex processes.

# Complex example(1)

Flow chart

The above diagram can be expressed as the following EL rules:

<chain name="chain1">
    THEN(
        A,
        WHEN(
            THEN(B, C),
            THEN(D, E, F),
            THEN(
                SWITCH(G).to(
                    THEN(H, I, WHEN(J, K)).id("t1"),
                    THEN(L, M).id("t2")
                ),
                N
            )
        ),
        Z
    );
</chain>

I believe most people should be able to understand, but if you re-optimize with sub variables, it will be more clear, the above can be optimized into:

<chain name="chain1">
    item1 = THEN(B, C);
    item2 = THEN(D, E, F);
    item3_1 = THEN(H, I, WHEN(J, K)).id("t1");
    item3_2 = THEN(L, M).id("t2");
    item3 = THEN(SWITCH(G).to(item3_1, item3_2), N);
    
    THEN(
        A,
        WHEN(item1, item2, item3),
        Z
    );
</chain>

Is it much clearer?

If you already understand the above example, let's look at a more complex example

# Complex example(2)

Flow chart

The above diagram can be expressed as the following EL rules:

<chain name="chain1">
    THEN(
        A,
        SWITCH(B).to(
            THEN(D, E, F).id("t1"),
            THEN(
                C,
                WHEN(
                    THEN(
                        SWITCH(G).to(THEN(H, I).id("t2"), J),
                        K
                    ),
                    THEN(L, M)
                )
            ).id("t3")
        ),
        Z
    );
</chain>

I think some people will be confused about the above expressions, and it takes half a day to count the parentheses. Of course, if you study it carefully, you should be able to understand it.

For such expressions that are difficult to read, the official recommendation is to split them into sub-processes or sub-variables. Below I optimize it by splitting the sub-variables:

<chain name="chain1">
    item1 = THEN(D, E, F).id("t1");
    
    item2_1 = THEN(
        SWITCH(G).to(
            THEN(H, I).id("t2"),
            J
        ),
        K
    );
    
    item2_2 = THEN(L, M);
    
    item2 = THEN(C, WHEN(item2_1, item2_2)).id("t3");
    
    THEN(
        A,
        SWITCH(B).to(item1, item2),
        Z
    );
</chain>

tip

The above 2 examples can be found in the test case in the source code, you can run and test.

Complex case one:com.yomahub.liteflow.test.complex.ComplexELSpringbootTest1

Complex case two:com.yomahub.liteflow.test.complex.ComplexELSpringbootTest2

# Summarize

LiteFlow's EL rule syntax is simple, but it can describe most scenarios. Try to keep your rules as simple as possible.

In actual scenarios, if you encounter complex processes, you can use sub chain or sub variables to simplify your entire rules. Make your rules elegant and easier to read!

Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🍂Use sub variables
🌻About semicolons

← 🍂Use sub variables 🌻About semicolons→

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