My micro-workflow engine design and micro-workflow engine design

Source: Internet
Author: User

My micro-workflow engine design and micro-workflow engine design
I. Preface

When it comes to workflows, many people will think of OA. Indeed, OA is a typical workflow application, but workflow is not limited to OA. workflow should be regarded as a basic framework software, it is mainly used for process reengineering and optimization, and has a broad application field. There are a lot of excellent open-source workflows in java, such as activit5 and jpbm4, but there is almost no satisfactory workflow engine available under. net. Of course not. net is not open-source, but some are open-source in China, but after reading the code, there will be no interest at all, not to mention the quality of the code, but also introduced a lot of things, it is also very difficult to apply in projects. In view of this, I decided to develop a. NET micro workflow engine by myself.

Ii. Basic description

Why is it a micro workflow engine? It is ultra-lightweight, so it is easy to use in projects. For example, if there is only one library dll, the size may be several hundred kb to 1 MB. But let's look at the workflow system first, it is too big. It should include:
1. Workflow Engine
2. workflow designer
3. Workflow Management System
4. Form Designer

Currently, I only implement the core engine, and the process definition can only be edited in xml and then read to the engine or directly defined in the database, but the entire process can flow normally. As for the process designer, Form Designer, and workflow management system, I am able to develop them slowly. Here, I completed only a small part, but it is the core of the workflow and can be easily embedded into the business system for application.

The engine mainly supports parsing workflow definitions and flow. The workflow definition file describes the interaction logic of the business. The workflow engine parses this + workflow definition file to transfer the business according to the interaction logic of the business. The workflow engine is usually designed by referring to a model, flow Through scheduling algorithms (process initiation, termination, suspension, and restoration ), various scheduling algorithms are used to transfer links (merging, splitting, selection, and conditional selection of links ).

3. Initial impressions

1. Starting from the concept, we can't see it anymore. Let's take a simple example to see how to create a project and reference my workflow engine class library (Chitu. Bpm. dll named Chitu ).
Configure the Process Engine (in Global. asax. cs) at project startup as follows:

// Initialize the process engine
BpmConfiguration
     .Instance ()
     .Config (@ "C: \ Configration \ BpmConfig.xml")
     .Start ();

When used in a project, such as creating a process definition:

// Get workflow context
var bpm = new BpmContext ()
     .UseTransaction (true)
     .SetActor ("Xiao Qin");

// New process definition
bpm.NewProcessDefinition ("Leave Process")
     .SetXmlFile (@ "C: \ Definition \ demo1.xml")
     .SetCategory ("Category 1")
     .SetEffectDate (DateTime.Now)
     .SetExpireDate (DateTime.Now.AddDays (180))
     .SetMemo ("memo1")
     .Create () // Create process definition, only generate bpm_definition_process table
     .Parse () // Parse the xml
     .Deploy (); // Release process

Start Process:

// Start process
var process = bpm.NewProcessIntance ("Leave Process ID", "Xiao Qin (Business ID)"); // Create a process instance
process.SetVariable ("Process variable 1", "Value 1"); // Set the process variable
process.Start ();

The manual task node is transferred to the next step:

//mission completed
var task = bpm.LoadTaskInstance ("Task ID");
task.SetVariable ("Task Variable 2", "xx");
task.Signal (); // Trigger token flow

All operations are concentrated in BpmContext through the Facade mode, which is simple and convenient.

2. Next, let's take a look at the XML defined in the process. Below is a process I fabricated to put all kinds of nodes into it.

<? xml version = "1.0" encoding = "UTF-8"?>

<process name = "model room decoration process">
  
  <start name = "renovation application">
    <transition to = "decoration plan design">
      <action class = "Namespace.MyActionHandler"> </ action>
    </ transition>
  </ start>

  <task name = "decoration plan design">
    <transition to = "Review of decoration plan">
      <action script = "log.Debug ('Renovation plan review action test');"> </ action>
    </ transition>
  </ task>

  <decision name = "decoration plan review">
    <transitions>
      <transition to = "decoration preparation" condition-expression = "variable.pass == true"> </ transition>
      <transition to = "decoration plan design" condition-expression = "variable.pass! = true"> </ transition>
    </ transitions>

    <events>
      <action event = "enter" class = "enterHandlerClass"> </ action>
      <action event = "leave" class = "leaveHandlerClass"> </ action>
    </ events>

    <assignments>
      <assignment owner = "{process.starter}"> </ assignment>
    </ assignments>

    <variables>
      <variable type = "boolean" name = "IsPass" access = "read, required"> </ variable>
    </ variables>
  </ decision>
 
  <fork name = "decoration preparations">
    <transition to = "Signing of decoration contract"> </ transition>
    <transition to = "Waiting for decoration workers in place"> </ transition>
    <transition to = "Budget for decoration materials"> </ transition>
  </ fork>

  <sign name = "Decoration contract signing" necessary = "false" async = "true">
    <transition to = "decoration construction"> </ transition>
  </ sign>

  <wait name = "Waiting for decoration workers in place">
    <transition to = "decoration construction"> </ transition>
  </ wait>

  <task name = "Decoration Material Budget">
    <transition to = "Material Procurement Sub-Process"> </ transition>
  </ task>

  <subflow name = "Material Procurement Sub-Process">
    <transition to = "decoration construction"> </ transition>
  </ subflow>

  <join name = "decoration construction">
    <transition to = "Construction acceptance / payment"> </ transition>
  </ join>

  <auto name = "Construction Acceptance / Payment">
    <transition to = "decoration completed"> </ transition>
  </ auto>

  <end name = "decoration completed">
  </ end>

  <events>
    <action event = "process-start" class = "TestStartHandler"> </ action>
    <action event = "process-end" class = "TestEndHandler"> </ action>
  </ events>

  <variables>
    <variable type = "string" name = "start_id" access = "readonly, required"> </ variable>
    <variable type = "string" name = "start_person"> </ variable>
  </ variables>
</ process> 

The defined root node is process, and each task node is in the process. The task nodes are divided:
Start Node
Auto Node
Task manual Node
Decisioin decision Node
Fork divergence Node
Join aggregation Node
Sublfow subflow Node
Sign Node
Wait Node

The task node can contain the transition action and the assignment variable definition (variable)
Actions include: 1, class 2, script 3, SQL 4, webservice 5, and expression
In script or expression, you can directly access the process. xxx attribute, task. xxx attribute, or variable. xxx attribute to simplify the use of dynamic c # statements.
Of course, there are many other attribute definitions in the XML definition, which I have not listed here. I will use them later for further consideration.

3. For data design, here is only the table required for flow of processes, and there is no relationship between tables.
// Signalpublic void Signal () {fromTask. leave (executeContext);} // Leavepublic void Leave (ExecutionContext executionContext) {transition in the Task class. take (executionContext);} // Take (ExecutionContext executionContext) {toTask in the Transition class of the route. enter (executionContext);} // Enterpublic void Enter (ExecutionContext executionContext) {Run (executionContext );}

At this point, the token is successfully transferred from one node to the next node. the token transfer is the key to the workflow. Of course, the processing of different nodes is different, the most complex is the number of divergent nodes and aggregation nodes. I will introduce it here and will not introduce it to you in detail.

D. Currently, our engine provides the following functions:
1. Explain the Process Definition
2. Control Process instances-creation, activation, suspension, and Termination
3. control flow scheduling
4. Custom Actions and event Publishing
5. process and work Variable Processing
6. Task plans, such as delayed start and task expiration
7. Delegate services and commission agents
8. roll back the service to any node or recall
9. Message Service, such as claim notifications, to-do reminders, and reminder messages...
10. Process Task Monitoring Service
11. log processing and history
12. Task Assignment and claim
13. participant organization model interface

V. Summary

Currently, my workflow engine is still being improved. I will summarize its advantages and disadvantages:
Advantages:
1. It is a super lightweight or micro workflow engine, and it is green and pollution-free. It has only one dll, And the size is only about 1 MB.
2. It currently supports SQL Server, MySql, Oracle, SQLite, PostgreSql, and other databases
3. In terms of shape, although it is micro-sized, It is not micro-functional. Its design combines modern OA and traditional workflows to basically implement most of our functional needs.
4. It is actually designed for developers. As you can see from the instance code above, its interfaces are centralized, streamlined, and friendly, this makes it easy for developers to understand and use. Therefore, it is more suitable for Embedded Development in projects.
Disadvantages:
1. It does not have a process designer, a management system, or a Form Designer. At best, it can only be regarded as a class library and can be used instead.
2. The first internal version has just been completed and is currently only used in our internal projects, so it is not mature enough, although we will continue to improve and improve it.
3. Lack of successful applications.
For ourselves, these shortcomings are part of our continued efforts and may require a lot of time to complete. Currently, we do not plan to open source. When it becomes stable and mature, we will consider whether it is open source. If you have good suggestions or some questions, I would like to answer them, or if you are designing and developing your own workflows, we can communicate with each other.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.