Use of Flowable Workflow Engine (0 Revelation)

Hits: 0

Use of Flowable [Workflow Engine] (0 Revelation)

First, let’s first-hand the standard three-link, what is flowable, what can flowable do, how to use it, or see the documentation link for a detailed introduction

Why use workflow:

In traditional business code, there are often some complete business processes, and the changes in the state of these processes are generally implemented through state machines, that is, A state –> B state –> C state. For traditional processes, such as the payment process, first place an order, then pay, deduct inventory, etc., we generally code directly to change the status step by step.
If our product changes are more flexible and some new nodes need to be added to the business process, then we need to modify some of the previous logic. Give a pseudo code to explain.

original code

void actionA(){
   state = a;
}

void actionB(){
    if(state == a){
        state = b
    }
}

modified code

void actionA(){
    state = a;
}
void actionA2(){
    if(state == a){
        state = a2;
    }
}
void actionB(){
    if(state == a2){
    //if(state == a){
        state = b
    }
}

It can be seen that we add a new task node, but we may need to modify other logic that has been written. If there are many such changes, it is definitely not good. So is there any way to make the business code unaware of the business process? No matter how the business process is changed, I only need to perform different operations on different types of task nodes. When will the technology end? The answer is the workflow engine.
The basic idea of ​​the workflow engine is to save the configured process in the database. We replace the state machine with the process control of the process engine. We only need to do the corresponding things when each node of the process arrives, and we don’t need to care what the next node is. What is the previous node.

Execution process of flowable workflow engine

Since we want to use the workflow engine, we need to tell the process engine about our business process. After the process engine knows our business process, we need to start the process at a reasonable time. There are countless task nodes in the process, and we can do different things at different task nodes. The simple workflow is as follows

  • The front-end configuration process, the process configuration information is given to the back-end in XML or JSON format
  • The backend calls the deployment method of the process engine, the deployment process
  • The backend calls the process engine’s initiating process method to initiate a process. The process engine advances the process to the first task node according to the process information we configured.
  • Each task node of the process engine can emit an event when it arrives, and we can handle the logic when some tasks arrive in different events
  • The backend calls the push process method of the process engine to push the process, and the process engine will push it to the next task node
  • Repeat the above operations until the end of the process

Let’s modify the code of the previous state machine, and we can see that the judgment of the state machine is gone, but the listeners set at different nodes of the process execute the business logic. The process engine controls the business reversal, and the executed tasks will not be executed again, so we can task a task node as a state, and after the state advances, our business logic will be adjusted differently.

class Service{

    void actionA(){
        ...
    }

    void  actionB () {
        ...
    }

    void actionC(){
        ...
    }
}

class  ATaskListener {

    Service service = new Service();

    @Override
    public void consumer(Object obj){
        service.actionA();
    }
}

class BTaskListener{

    Service service = new Service();

    @Override
    public void consumer(Object obj){
        service.actionB();
    }
}

class BTaskListener{

    Service service = new Service();

    @Override
    public void consumer(Object obj){
        service.actionB();
    }
}

Summarize

We can see that the workflow is still relatively intrusive to the code, but relatively speaking, the maintenance of our state is very safe and reliable. The workflow is based on the distributed characteristics of the database, and it also solves some distributed problems. Out of the box, some concurrency issues of a task being executed at the same time have been dealt with.

In addition to the above, the most important task of the workflow is to do approval. The workflow engine provides a wealth of APIs, reviewers, agents, approval groups, different types of process components and other concepts.

You may also like...

Leave a Reply

Your email address will not be published.