LiteFlow component process engine framework

Product requirements:

Take Jingdong of Dongge's house as an example. Now I have a group of good guys who only need 998. Every 618 has a big promotion 668, double 11 888, double 12 180

Primary development

See the demand shout, so simple look down on me? So the operation was as fierce as a tiger. It wrote:

      if ("618".equals(day)){
            System.out.println("668");
        }else if ("11.11".equals(day)){
            System.out.println("888");
        }else if ("12.12".equals(day)){
            System.out.println("180");
        }else{
            System.out.println("998");
        }

Intermediate development

image.png

Good guy, you are brother ifelse, so you come up with a strategy

public interface NodeComponent {
  void  process() ;
}
@Component
public class AComponent extends NodeComponent {
    @Override
    public void process() {
        /**
         * Logical omission here
         * 
         */
        System.out.println("618");
    }
}
@Component
public class BComponent extends NodeComponent {
    @Override
    public void process() {
        /**
         * Logical omission here
         * 
         */
        System.out.println("11.11");
    }
}
//12.12 is omitted below
//Mainstream process
@Component
public class TestFlow {
    @Resource
    private Map<String, NodeComponent> map;
    public void run(String name) throws Exception {
        for (Map.Entry<String, NodeComponent> entry : map.entrySet()) {
            String key = entry.getKey();
            if (StringUtils.equals(name,key)){
                entry.getValue().process();
            }
        }
    }
}

Something's wrong with the product again

I also have A system requirement as follows: undefined needs to perform verification before query. First perform A verification - > b verification - > C verification - > d verification. What should I do at this time Chain of responsibility? Undefined if the process changes undefined B check - > A check - > C check - > d check undefined or undefined B check - > d check - > A check - > cundefined, think about it? Do you want to make A meal? Don't worry, here comes the new thing... Look down > > > > > > >

LIteFlow comes on stage

image.png

About LiteFlow

Liteflow is designed to decouple complex logic. If you want to write or reconstruct complex business logic, liteflow is the most appropriate. It is a lightweight and fast component-based process engine framework, which helps decouple business code, make each business segment a component, and support hot loading rule configuration to realize immediate modification.

Using Liteflow, you need to split the complex business logic into small components according to code fragments, and define a rule process configuration. In this way, all components can be configured according to your rules for complex flow.

advantage:

  • Editing weapon
  • Regular lightweight
  • Elegant and stable
  • Flexible expansion

characteristic:

  • It is a powerful tool for decoupling complex business and provides a unified implementation protocol for all components
  • The process is arranged based on the rule file and can be hot arranged
  • The framework supports zookeeper process configuration and push the modified content immediately
  • It can freely extend and configure persistent sources and provide extension interfaces
  • It supports the automatic assembly of spring boot, spring configuration and non spring projects
  • It provides two modes: serial and parallel, and provides common expression statements
  • Provide stepless nested sub process mode
  • Data slot high concurrency isolation mechanism
  • With simple monitoring, you can know the running time of each component

architecture design

image.png

What scenarios does Liteflow apply to

Liteflow is applicable to businesses with complex logic, such as price engine, order placing process, rule verification, etc. these businesses often have many steps. These steps can be divided into independent components according to business granularity for assembly reuse and change. Using liteflow, you will get a system with high flexibility and strong scalability. Because the components are independent of each other, the risk of moving the whole body by changing one place can also be avoided.

Gitee warehouse of Liteflow: https://gitee.com/dromara/liteFlow

Github warehouse in Liteflow: https://github.com/dromara/liteflow

Use document address

liteflow integration in spring boot

  • Introduce dependency
     <dependency>
          <groupId>com.yomahub</groupId>
            <artifactId>liteflow-spring-boot-starter</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
  • Write process node
@Component("a")
public class AComponent extends NodeComponent {
    @Override
    public void process() {
        String str = this.getSlot().getRequestData();
        System.out.println(str);
        System.out.println("Acomponent executed!");
        this.getSlot().setOutput(this.getNodeId(), "A component output");
    }
}
@Component("b")
public class BComponent extends NodeComponent {
    @Override
    public void process() {
        try {
            Thread.sleep(400L);
            String[] temp = new String[1000];
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Bcomponent executed!");
    }
}
  • Process test
@Component
public class TestFlow{
    @Resource
    private FlowExecutor flowExecutor;
    @Override
    public void run(String... args) throws Exception {
        Slot slot = flowExecutor.execute("chain3", "it's a request");
        System.out.println(slot);
    }
}
  • Create the flow.xml file src/main/resources/config/flow.xml

image.png

<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <chain name="chain1">
        <then value="a,cond(b|d)"/> <!-- cond Is a condition node, according to cond The logic in determines the route to b Node or d node,Multiple can be configured -->
        <then value="e,f,g"/>
    </chain>
    <chain name="chain2">
        <then value="a,c"/> <!-- then Indicates serial -->
        <when value="b,d"/> <!-- when Indicates serial -->
        <then value="e,f,g"/>
    </chain>
</flow>
  • application.properties
liteflow.rule-source=config/flow.xml
#------The following are not required-------
#The number of slot s. The default value is 1024
liteflow.slot-size=2048
#The maximum waiting time of an asynchronous thread is seconds (when only), and the default value is 15
liteflow.when-max-wait-second=20
#Whether to enable monitoring log printing. The default value is false
liteflow.monitor.enable-log=true
#The storage size of the monitoring queue is 200 by default
liteflow.monitor.queue-limit=300
#Monitor how much execution is delayed at the beginning. The default value is 300000 milliseconds, that is, 5 minutes
liteflow.monitor.delay=10000
#Monitoring log printing is executed every time. The default value is 300000 milliseconds, that is, 5 minutes
liteflow.monitor.period=10000

Posted by citytours on Mon, 22 Nov 2021 18:23:15 -0800