Kstry can more intuitively display the intricate method call relationship that originally existed in the code in the form of a visual flow chart, and provides a configuration method to control the visible method nodes. The framework cannot exist outside of program execution, and can only take effect and be used in methods and method calls, such as a call of a certain interface. Unlike task flow frameworks such as Activiti and Camunda, task instances are not stored and managed outside of program execution.
In different usage scenarios, because of their different functions, they can be understood as different frameworks. Kstry is:
🟢【Process orchestration framework】Provide the visualization capability of what you see (flow diagram) is what you get (code execution), customize the process protocol, and support hot deployment of process configuration
🟢【concurrency framework】The process can be upgraded from serial to parallel through minimal operations, supporting task splitting, task retrying, task downgrading, subtask traversal, specifying the timeout period of the process or task
🟢【Microservice business integration framework】Support custom instructions and task scripts, and can be responsible for the assembly of various basic ability components
🟢【lightweightTMF2.0frame】The following three steps can be used to meet the different demands of various businesses on the same interface: abstract capability resources, define and authorize the abstracted capability resources to business roles, different scenarios of the same process can be matched with different roles and then Execute the capacity resource tasks under it
What are the characteristics of Kstry?
🟢【business visibility】The well-arranged graphical model is the real execution link of the code, through what you see ( Graphical model ) is the result ( code execution ) way to build a common language bridge between technology and business, so that the communication between each other will be smoother
🟢【Flexible configuration】Provides configuration components such as start event, end event, service node, script node, exclusive gateway, inclusion gateway, parallel gateway, conditional expression, custom instruction, sub-process, interceptor, etc., which can support abnormally complex business processes
🟢【dynamic configuration】Main processes, sub-processes, roles, variables and other components support dynamic configuration, which can be changed dynamically without starting the application. Dynamic configuration supports all storage media including open source and company self-developed
🟢【high adaptability】Contains two sets of process definition APIs, BPMN visual configuration file and code. On the premise of ensuring visual configuration, it also supports parsing process configuration files in any format through code, so as to combine suitable front-end products to build a personalized process configuration platform
🟢【Easy operation and maintenance】The service node supports the definition of timeout, retry times, failure degradation, strict mode, resource iteration, etc., which can meet the strict requirements of application stability in the production environment
🟢【excellent performance】The bottom layer uses the Spring tool set to call the service node, and the task execution consumption is equivalent to that of the Spring aspect
🟢【Seconds become asynchronous】Seamless connection SpringFlux.No code changes required, only configured on parallel or included gateways open-async=true
all subsequent sub-links can be parallelized under the premise of ensuring thread safety
🟢【smooth interaction】Introduce the concept of StoryBus and its four data domains.Data access and interaction between nodes can be safe, flexible and convenient
🟢【business abstraction】Introduce concepts such as resources, permissions, roles, etc., build customized business identities, and provide technical support and solutions for abstract business capabilities
🟢【process backtracking】It can record important data such as node execution sequence, node time consumption, input parameters, output parameters, abnormal information, etc. at zero cost, and supports custom execution monitoring logs
What problems can Kstry solve?
🟢【business ambiguity】The code is complex and the model documents are not updated in time, so that new students and non-technical students cannot understand the business status in a short time. There is a divergence between technical and non-technical understanding of the same business without knowing it.Even the business owner can’t describe the business he is responsible for very fluently
🟢【code mess]There are many domain objects involved in the project. There are not only complex front-back dependencies between objects, but also no obvious boundaries between them. The code is even more chaotic and difficult to maintain after multiple iterations.
🟢【poor performance】A certain business link is composed of a series of subtasks, among which some subtasks that take a long time and have no dependencies between data need to be processed in parallel, but suffer from the lack of a streamlined and code-free concurrency framework
🟢【The death of the platform】Maintenance of platform-based products provides basic services for many upstream business lines, but it is difficult to respond to the customization needs of various business parties in a short period of time, let alone how to do a good job of isolating the platform and business, business and business
🟢【Backtracking Difficulty】It is difficult to track the status of business flow data, and it is even more difficult to troubleshoot occasional problems that only exist in the online environment.An ability to save important node data through simple operations is needed, which is comparable to systematic log printing after fine-tuning links
🟢【complex testing】The business scenarios are diverse, and there are many complex links that are difficult to be covered by the test.Or the three-party data Mock is difficult, and the test cost remains high
Kstry component concept introduction
1. Configure domain and run domain
Simply speaking, the configuration domain is to configure the process through visualization, code, or script, and the execution domain is to execute according to the configured rules.
Conceptually, program execution is usually the call between methods, but in Kstry it is the relationship between task nodes (the reason why it is conceptual is because whether Kstry is used or not, the actual execution carrier of the program They are all methods in the class, and task nodes and methods are also in one-to-one correspondence). The process configuration before task execution determines what kind of relationship will be generated between nodes during actual execution. The process configuration before the program is executed is the configuration domain, and the framework parses the process configuration and guides the task nodes to call successively when the program is executed, which is the execution domain.
2. Process definition
Process definition is the work that needs to be done in the configuration domain before the actual execution of the program. It consists of start events, end events, service nodes, gateways, and directed line segments connecting these components. The compiled graphic model is the real execution link of the code, through what you see ( Graphical model ) is the result ( code execution ) way to build a common language bridge between technology and business, making communication between each other smoother.
onlybpmnPath
In a process configuration approach, the following visual flow chart is the defined process, and it is also used to guide the execution of the actual circuit of the program.ProcessLink
After its appearance, the framework provided users with the ability to customize the process. In versions after 1.x, the BPMN visual flow chart is also parsed intoProcessLink
object to take effect, and the BPMN visual process at this time exists as a subset of the process definition.In more cases, users can create by coding, parsing various configuration files, etc.ProcessLink
Instance, which is finally delivered to the frameworkProcessLink
The instance will be used as a process definition to guide the execution of the program.
Kstry provides three ways to define process configuration, namely:
🟢【Basic process configuration】Specify@EnableKstry
AnnotatedbpmnPath
property to scan bpmn configuration files in the specified directory
🟢【Basic process configuration】createProcessLink
The instance is placed in the Spring container
🟢【Dynamic process configuration】accomplishDynamicProcess
interfacegetProcessLink
method
The processes defined in the previous two methods are basic process configurations that must be defined before the application starts, and the basic process cannot be modified unless the application is restarted.according tostartId
The last method will take effect when the process configuration cannot be obtained in the basic process configuration library. The way to obtain the process configuration is dynamic.startId
returnProcessLink
In the example, the required process configuration information can be obtained by any means such as http or rpc call, relational or non-relational database query, subscription message queue, subscription registration center, and company-defined storage medium query.
The reason why the dynamic configuration capability of the process is not realized by dynamically changing the basic process configuration library is as follows:
🟢【safety】Process configuration may be divided into important levels. The core process configuration is strictly controlled and cannot be changed at will, so this type of configuration should be placed in the code and not allowed to be changed at will.If found in the process configuration base library withstartId
For the matching process, the dynamic acquisition part will be invalid, so as to ensure the absolute security of the process. Even if there is some extended logic in the core process that needs to be dynamically acquired, it can also be implemented in the form of a dynamic sub-process.
🟢【compatibility】Dynamic configuration may be more suitable to use the registration center to store and maintain, so that when changes occur, relevant applications can be notified quickly and promptly to make process changes. However, there is not a registry that all companies use. In addition to open source products, there are also self-developed companies. It is unrealistic to support all of them. The same is true for choosing other middleware products. So the way to solve this problem is to provide an entry to dynamically obtain the process configuration. As for where to obtain the process configuration, it will vary from person to person.
3. Sub-process definition
As the name suggests, the subprocess concept is easy to understand. When reusable or complex link fragments appear in the process, these fragments can be extracted to define sub-processes. The parent process can refer to the sub-process through the sub-process Id. There are also three ways to define sub-processes, namely:
🟢 【Basic subprocess configuration】Specify@EnableKstry
AnnotatedbpmnPath
property to scan bpmn configuration files in the specified directory
🟢【Basic subprocess configuration】createSubProcessLink
The instance is placed in the Spring container
🟢 【Dynamic subprocess configuration】accomplishDynamicSubProcess
interfacegetSubProcessLinks
method
The main process is divided into basic and dynamic, and correspondingly there are basic and dynamic sub-processes. The following figure shows whether the two are allowed to be quoted when they are combined:
🟢 The basic process can only refer to the basic sub-process configuration, and the dynamic process can refer to the basic sub-process and dynamic sub-process configuration
🟢 The two sub-processes can refer to each other in their respective regions, and the basic sub-process configuration can be referenced in the dynamic sub-process, and vice versa is not allowed
Notice:When sub-processes refer to each other, there must be no circular dependencies, otherwise an exception will occur
4. Service node
The framework divides domain boundaries and realizes business functions by defining service nodes. A service node is the smallest unit of process orchestration and task execution. The service nodes connected by directed line segments in the configuration domain form the main process or sub-process. The node in the running domain corresponds to a method in the class component, and the process execution is actually a process in which the methods corresponding to the nodes are called one by one.
If you want to define a service node in the framework, you first need to define the component class where the service node (that is, the method) is located. Component classes are hosted in the Spring container, and there are two ways to define them:
🟢 The class is placed where the Spring container can scan and add@TaskComponent
annotation
🟢 is loaded as a Spring component and implementedTaskComponentRegister
interface
After the component class is defined, the public methods in it are added@TaskService
Annotations are service nodes.@TaskService
in the comment@Invoke
Attributes can specify the number of service node retries, timeout period, downgrade method, whether the Story is allowed to continue to execute after an exception, etc.
Notice:The method modified by @TaskService must bepublic
otherwise it cannot be recognized
As mentioned earlier, Kstry is both a process orchestration framework and a lightweight TMF2.0 framework. There are also two ideas related to the understanding of service nodes:
🟢 If it is just process arrangement, the whole process can be regarded as a complete task, and the service node is the subtask
🟢 Another way of thinking is more suitable for platform products. A complete process definition can be regarded as a solution provided by the platform for a certain business activity.The service node is the service in the solution (in the figure below, loading product information, store information, marketing information, and calculating prices are all services). Under the service, multiple capability points can be defined, which are marked in the code dimension@TaskService
In the annotated method,name
Service nodes with the same attributes are the same service, differentability
Attributes distinguish different ability points. For different businesses, different capability points under each service can be matched to complete personalized business demands.For more specific concepts involved, please refer to the introduction of capabilities & roles below
No matter which way of thinking, the division principle of service nodes is to achieve business isolation as much as possible. The process of a business request going through various business activities to finally get the result is dynamic. The dynamic business process is reasonably segmented by using the boundary. The product is the service node, which is also the bounded context in the domain driver. Understanding the characteristics of the following bounded contexts can guide how to better define service nodes:
🟢 Minimal complete: It has the minimum dependency conditions to complete its own mission goals, no need to help other service nodes, and avoid unnecessary dependencies
🟢 self-fulfillment: According to the resource information currently mastered by the service node, judge whether the expected goal is consistent with its own mission goal, and decide whether it should perform this duty
🟢 stable space: Reduce the impact of external changes on the interior of the service node
🟢 independent evolution: Reduce the impact of service node changes on the outside world
5. Gateway
There are three types of gateways: exclusive gateways, inclusive gateways, and parallel gateways
The gateway has the function of controlling the execution of the process. Different gateways have different characteristics. Including gateways and parallel gateways, subsequent processes can be configured to execute concurrently.The combination of various gateways and service nodes can realize very complex business scenarios
5.1 Exclusive Gateway
🟢 An exclusive gateway can only accept one indegree. That is to say, there is and only one arrow can point to the exclusive gateway.The same is true for service nodes
🟢 There can only be one in-degree for an exclusive gateway, and multiple out-degrees. The above conditional expression will be parsed and executed, if there is no conditional expression, it will be true by default
🟢 When the exclusive gateway has multiple out-degree-related expressions that are resolved to true, it will select the first branch that is true to continue downward execution, and the others will be ignored and no longer executed.Before and after the out-degree does not mean the order of the out-degree when the program is parsed, so the exclusive gatewayIf multiple out-degrees are true, the running result is uncertainshould try to avoid this happening
🟢 When all the expressions on the out-degree resolve to false, an exception will be thrown and the process will end
🟢 Since only one link is finally executed behind the exclusive gateway, the exclusive gateway does not support enabling asynchronous, because it is meaningless
5.2 Parallel Gateway
🟢 Parallel gateway can receive and merge multiple in-degrees
🟢 Parallel gateways require all ingress to be executed before proceeding, otherwise it will wait forever.Therefore, it is necessary to confirm that all ingress of the gateway must be reachable before use.
🟢 When using parallel gateways, generally two parallel gateways will appear together.In the front, a branch is disassembled into multiple branches, and then multiple branches are aggregated
🟢 Parallel gateway support for starting asynchronous processes.When asynchronous is not enabled, the multiple branches split by the parallel gateway are still executed by the current thread. After the asynchronous process is enabled, all branches behind the gateway will create asynchronous tasks and submit them to the thread pool for execution
🟢 If there is a conditional expression behind the parallel gateway, the expression will be ignored, no matter whether it is set or not, it will not be parsed, and it will default to true
5.3 Include Gateway
🟢 The included gateway is the same as the parallel gateway, which supports starting asynchronous processes and receiving multiple inbounds
🟢 Including the restriction that the gateway does not have to reach all the in-degrees. After waiting for all the in-degrees to be executed or knowing that some of the in-degrees may not meet the conditions and no longer execute, it will continue to go down
🟢 Conditional expressions can be set for the out-degree behind the included gateway, and the expression parsing rules are the same as those for the exclusive gateway out-degree parsing rules
6. Process Story
The process definition describes how the current process is executed and belongs to the content of the configuration domain, while the process story is executed one after another according to the defined process, which belongs to the content of the operation domain. The two can be understood as the relationship between the class definition and the object instance in the code. The process definition is the class file to describe the shape and content of the object, and the object is an instance created according to the class file.
framework providedStoryEngine
instance to parse the process execution Story, which is hosted in the Spring container and can be obtained by any way of obtaining Spring BeanStoryEngine
object. The object provides synchronous and asynchronous ways to execute the Story. It is worth mentioning that a timeout must be set before synchronous and asynchronous execution. The default timeout is 3s. When time-consuming scenes or debugging codes can be adjusted to an appropriate timeout as needed.
7. StoryBus
The service nodes in the process definition are independent individuals, and there is no dependency relationship between them, and the data cannot be directly transmitted. However, a business request is completed by the cooperation and mutual cooperation of all nodes. At this time, it is necessary to understand the concept of StoryBus. StoryBus is the data bus of the process Story, and its life cycle will be consistent with the process Story.
🟢 Each service node can obtain the required parameters from the StoryBus, and after execution, notify the required results to the StoryBus
🟢 There are four data fields in StoryBus, they are:
🔷 req: Save the request object passed in by the request, and the request object itself will not change.But the value inside the object is allowed to be updated through the later variable notification
🔷 sta: Save the variable generated after the node is executed. Once set, it will no longer change. If there is a repeated setting, there will be a warning log (when only the reference of the object is in the sta domain, the fields in the object can still be updated. This point same as req)
🔷 var: Save the variable generated after the node is executed, which can be replaced repeatedly. The properties of the fields in the object are the same as above
🔷 res: Save the final result and return it to the caller as the final result after the Story execution is completed (Starting from version 1.0.9, result is renamed to res)
🟢 Service node through annotation (@NoticeXxx
,@XxxTaskParam
,@XxxTaskField
Xxx generally refers to the four domains mentioned above)andScopeDataOperator
Two ways to access variables from StoryBus
🟢 In node out-degree, conditional expressions can be defined to directly refer to these four fields for conditional judgment, such as appearing in process arrangement:res.img != null
,req.source!='app'
🟢 The four scopes are protected by read-write locks, get acquires read locks, and notice acquires write locks to prevent concurrency problems
🟢 After the asynchronous mode is turned on, the subtasks created at the same time can read and write the variables in the StoryBus, soNodes with forward and backward dependencies in terms of data cannot be created into different subtasks executed in the same time periodwhen there are relevant demands, you can aggregate the nodes to ensure the sequence of data dependencies when the nodes are executed
8. Ability & Role
-
For platform services, you can first define and orchestrate a general link model, which is the process definition mentioned above
-
A certain service node in the model can expand different service capabilities ( For example, both business parties A and B need rake services, then you can define a rake service node, and then A business needs a proportional rake, while B business needs a step-by-step rake, then you can use the rake Expand two different rake capabilities on the service node )
-
The extended capabilities can be regarded as resources. All resources have a unique resource name, and the corresponding resource can be accessed by carrying a permission object containing a certain resource name ( Resources can also be called: extended service capabilities )
-
A batch of independent permission objects has a high maintenance cost, so all the permissions required by a certain business scenario can be aggregated in turn to form a role object
-
When providing platform capabilities, judge the specific business scenario or demand side according to the parameter identification, find the corresponding role, carry the role to execute the preset link model, and then complete the customized business appeal
-
See:RBAC mode
9. Process backtracking
Process backtracking can print the node execution log or execute a custom callback method after the link is executed and before the result or exception is obtained, which can deal with the following problems:
🟢 View the information of the running nodes, such as: execution sequence, node time consumption, input parameters, output parameters, exception information and other important data
🟢 Customize the process backtrace log, or print the detailed log when an exception occurs
🟢 Check whether the node execution, parameter settings, etc. are as expected.Because sometimes the result does not report an error, but it does not mean that the process must be correct
🟢 If there is a custom role operation in the link, check whether the final role meets expectations
#Kstry #Homepage #Documentation #Download #Process #Orchestration #Framework #Concurrency #Framework #Microservice #Business #Integration #Framework #News Fast Delivery