stepchain 通用业务流程流水线处理框架

Easter79
• 阅读 466

stepchain 通用业务流程流水线处理框架。

类似于Commons Chain和Commons Pipeline这样的Java Pipeline Step Chain用于组织复杂处理流程执行的流行技术。

Java Pipeline Step Chain like Apache Commons Chain and Commons Pipeline。 A popular technique for organizing the execution of complex processing flows is the "Chain of Responsibility" pattern。

gitee: https://gitee.com/zengfr/stepchain

github: https://github.com/zengfr/stepchain/

Repositories Central Sonatype Mvnrepository

Feature: 1、支持通用业务job、services子流程无限制拆分。 2、支持业务子流程串行化、业务子流程并行化,可配置化。 3、支持Config业务子流程开启或禁用、配置串行或并行以及并行数的统一配置。 4、支持业务流程以及子流程任意无限嵌套。 5、支持配置中心、缓存、统一数据接口、redis、Es、日志Trace等。 6、支持并行分支,支持条件分支if/else、switch、loop子流程. 7、支持Processor定时调度FixedRate、FixedDelay。 备注:只开源了通用部分(不影响使用),去除了有关框架组件包括:配置中心、缓存中心、数据接口以及业务相关DataMiddle等部分API。

Maven Dependency: Maven(Not Use Spring Boot): com.github.zengfr.project stepchain 0.0.7 Maven(Use Spring Boot): com.github.zengfr.project stepchain-spring-boot-starter 0.0.7 Gradle: compile group: 'com.github.zengfr.project', name: 'stepchain', version: '0.0.7' compile group: 'com.github.zengfr.project', name: 'stepchain-spring-boot-starter', version: '0.0.7'

interface Pipeline ChainBuilder StepBuilder Step Chain javadoc api文档 stepchain 通用业务流程流水线处理框架

1、StepChain 的中心思想是什么?如何做到通用的? 答: 1.1、任何业务逻辑处理抽象成1\input输入 2\ processor处理器 3\output输出.中间过程结果产生和组合成dataMiddle。 1.2、任何业务逻辑处理使用多个processor组合执行。

2、StepChain 如何并行和串行执行多个processor? 答: 串行step=pipeline.createStep();step.put(processors);//processors串行执行. 并行step=pipeline.createStep(4);step.put(processors);//processors同时4个并行执行.

3、Stepchain 如何创建processor? 3.1、实现 IProcessor 接口。 3.2、使用IProcessorBuilder: IProcessor<I, Boolean> createProcessor(Predicate predicate); IProcessor<I, Boolean> createProcessor(Consumer consumer); <I, O> IProcessor<I, O> createProcessor(Function<I, O> func);

4、StepChain 如何复用和组合processor? 4.1、使用IChainBuilder、IChain: 4.2、使用IProcessorBuilder: <A, B, C> IProcessor<A, C> createProcessor(IProcessor<A, B> first, IProcessor<B, C> second); <A, B, C, D> IProcessor<A, D> createProcessor(IProcessor<A, B> processor1, IProcessor<B, C> processor2, IProcessor<C, D> processor3);

5、StepChain 如何按条件复用和组合processor? 答: case1、已有trueProcessor\falseProcessor2个 创建 validator 则按条件执行2则之1. IConditionSelectorProcessor<String, Boolean, String> p3 = pipeline.createConditionValidatorProcessor(validator, trueProcessor, falseProcessor);

case2、已有processor 创建 validator 创建循环执行体,validator 返回false时终止执行。 IConditionLoopProcessor<String, String> p2 = pipeline.createConditionLoopProcessor(validator, processor);

case3、已有processor创建 switch 逻辑,根据selector返回的key执行某1分支branchProcessor如果返回的key不在分支中 则执行默认key对应的分支branchProcessor。 IConditionSelectorProcessor<String, String, String> p1 = pipeline.createConditionSelectorProcessor(selector); p1.setBranch(S key, IProcessor<I, O> processor); p1setDefaultBranch(S key);

case4、已有processor创建 if/else if/else 逻辑,根据validator返回的结果与result对比一致则执行分支branchProcessor,如果没有返回一致的 则执行默认分支branchProcessor。 pipeline.createConditionValidatorSelectorProcessor(); public interface IConditionValidatorSelectorProcessor<I,O> extends IProcessor<I, O> { void setBranch(IProcessor<I, Boolean> validator,Boolean result,IProcessor<I, O> processor); void setDefaultBranch(IProcessor<I, O> processor); }

public interface IStep extends IStepProcessor { void put(IStepProcessor processor);

void put(IStepProcessor<I>... processorArray);

void put(Collection<StepProcessor<I>> processors);

void put(IProcessor<I, Boolean> processor);

void put(IProcessor<I, Boolean>... processorArray);

void put(IChain<I, Boolean> chain);

void put(IChain<I, Boolean>... processorArray);

void put(Function<I, Boolean> func);

void put(Function<I, Boolean>... processorArray);

} public interface IChain<A, B> extends IProcessor<A, B> { IChain<A, C> next(IProcessor<B, C> process);

<C> IChain<A, C> next(Function<B, C> func);

} public interface IChainBuilder { <A, B> IChain<A, B> createChain(Function<A, B> func);

<A, B> IChain<A, B> createChain(IProcessor<A, B> processor);

<A, B, C> IChain<A, C> createChain(IProcessor<A, B> processor1, IProcessor<B, C> processor2);

} public interface IStepBuilder { IStep createStep();

<T> IStep<T> createStep(int parallelCount);

<T> IStep<T> createStep(String parallelCountConfigName);

}

StepChainSpringBootTest.java

PipelineTest.java 
Demo&Test you can use AbstractProcessor AbstractStepProcessor

import com.github.zengfr.project.stepchain abstract class AbstractProcessor<I, O> implements Processor<I, O>{} abstract class AbstractStepProcessor extends AbstractProcessor<A, Boolean> implements StepProcessor{}

import com.github.zengfr.project.stepchain.Chain; import com.github.zengfr.project.stepchain.Pipeline; import com.github.zengfr.project.stepchain.Step; import com.github.zengfr.project.stepchain.context.ContextBuilder; import com.github.zengfr.project.stepchain.context.UnaryContext; import com.github.zengfr.project.stepchain.test.context.SetProductContext; import com.github.zengfr.project.stepchain.test.context.SetProductDataMiddle; import com.github.zengfr.project.stepchain.test.processor.DiscountProcessor; import com.github.zengfr.project.stepchain.test.processor.FeeProcessor; import com.github.zengfr.project.stepchain.test.processor.IncreaseProcessor; import com.github.zengfr.project.stepchain.test.processor.InitProcessor; import com.github.zengfr.project.stepchain.test.processor.TaxProcessor;

public class PipelineTest { public static void testPipeline(IPipeline pipeline) throws Exception { //Demo精简版 只开源了通用部分(不影响使用) SetProductRequest req = new SetProductRequest(); SetProductResponse resp = new SetProductResponse(); SetProductDataMiddle middle = new SetProductDataMiddle();

SetProductContext context = new SetProductContext(req, middle, resp);
IStep<SetProductContext> step = pipeline.createStep();
step.put(new InitProcessor());
step.put(new TaxProcessor());
step.put(new FeeProcessor());
step.put(new IncreaseProcessor());
step.put(new DiscountProcessor());
step.put((c) -> {
    c.middle.Price += 10;
    return true;
});
step.process(context);
System.out.println(context.middle.Price);
}

public static void testPipeline2(IPipeline pipeline) throws Exception {
Function<UnaryContext<Integer>, Boolean> func = (context) -> {
        if (context.context == null)
            context.context = 1;
        context.context += 1;
        return true;

    };
    Function<UnaryContext<Integer>, String> func3 = (context) -> {
        if (context.context == null)
            context.context = 1;
        context.context += 1;
        return JSON.toJSONString(context.context);

    };
    UnaryContext<Integer> context = pipeline.createContext(12345678);
    IStep<UnaryContext<Integer>> step = pipeline.createStep();
    IStep<UnaryContext<Integer>> step2 = pipeline.createStep();
    IChain<UnaryContext<Integer>, Boolean> c2 = pipeline.createChain(func);
     
    IChain<UnaryContext<Integer>, String> c3 = pipeline.createChain(func3);
    Function<String, Integer> func4 = null;
    Function<Integer, String> func5 = null;
    Function<String, Boolean> func6 = null;
    IChain<String,Integer > c4 = pipeline.createChain(func4);
    IChain<Integer, String> c5 = pipeline.createChain(func5);
    IChain<String, Boolean> c6 = pipeline.createChain(func6);
    IChain<UnaryContext<Integer>, Boolean> c7 = c3.next(c4).next(c5).next(c6);
    
    step2.put(c2);
    step2.put(step);
    step2.put(func);
    //step2.put(c7);
    
    step2.process(context);
    System.out.println(context.context);
}
public static void testPipeline3(IPipeline pipeline) throws Exception {
    IProcessor<String, String> selector = null;
    IProcessor<String, Boolean> validator = null;

    IProcessor<String, String> processor = null;
    IProcessor<String, String> first = null;
    IProcessor<String, String> second = null;

    IConditionSelectorProcessor<String, Boolean, String> p3 = pipeline.createConditionValidatorProcessor(validator, first, second);
    IConditionLoopProcessor<String, String> p2 = pipeline.createConditionLoopProcessor(validator, processor);

    IConditionSelectorProcessor<String, String, String> p1 = pipeline.createConditionSelectorProcessor(selector);
}

@RunWith(SpringRunner.class) @SpringBootTest(classes = StepChainTestApplication.class) public class StepChainSpringBootTest { @Autowired protected IPipeline pipeline; @Test public void testPipeline() throws Exception { PipelineTest.testPipeline(pipeline); } @Test public void testPipeline2() throws Exception { PipelineTest.testPipeline2(pipeline); }

stepchain 通用业务流程流水线处理框架 stepchain 通用业务流程流水线处理框架 stepchain 通用业务流程流水线处理框架  stepchain 通用业务流程流水线处理框架  stepchain 通用业务流程流水线处理框架  stepchain 通用业务流程流水线处理框架

点赞
收藏
评论区
推荐文章
速看!今天我才知道,UUID还分五个版本
通用唯一识别码(英语:UniversallyUniqueIdentifier,缩写:UUID)是用于计算机(https://zh.wikiped
Wesley13 Wesley13
2年前
Activiti工作流简单入门
BPMN2.0BPMN最初由业务流程倡议组织(BPMI)定案,现在BPMI并入到OMG(ObjectManagementGroup)了,则由OMG建立规范和维护。BPMN2.0正式更名为(BusinessProcessModelAndNotation)业务流程符号和模型,也有人继续称呼为业务流程建模标记法(Busine
API 小达人 API 小达人
5个月前
流程测试用例的详细指南|Eolink Apikit 接口自动化测试
流程测试用例是为验证特定业务流程而设计和编写的测试案例,专注于检查系统或应用程序在执行某一业务流程时的正确性、稳定性和可靠性。一个业务流程可能涉及多个步骤、多个用户交互和多个系统组件的协作,流程测试用例有助于确保整个流程在各种情况下都能正常运行。在API自动化测试中,所有的测试用例都是以项目维度来进行管理,一个自动化测试项目可以从多个API文档项目中引用API信息来创建API测试用例。
何婆子 何婆子
3个月前
Camunda高级实战培训系列教程
Camunda高级实战培训系列教程download》chaoxingit.com/2231/Camunda是一个流行的开源工作流引擎,被广泛应用于业务流程管理(BPM)和业务流程自动化(BPA)。以下是一些高级实战的建议:理解Camunda模型:首先需要了
京东云开发者 京东云开发者
3个月前
打开java语言世界通往字节码世界的大门——ASM字节码操作类库
一、ASM介绍1、ASM是什么ASM是一个通用的Java字节码操作和分析框架。它可以用于修改现有类或直接以二进制形式动态生成类。ASM提供了一些常见的字节码转换和分析算法,可以从中构建定制的复杂转换和代码分析工具。ASM提供了与其他Java字节码框架类似的
乐和 乐和
2个月前
Camunda高级实战培训系列教程
Camunda高级实战培训系列教程download》chaoxingit.com/2231/Camunda高级实战:从理论到实践一、引言Camunda是一款流行的业务流程管理(BPM)平台,它提供了丰富的功能和工具,可以帮助企业实现业务流程的自动化和优化。
乐和 乐和
2个月前
基于 Vue3 ,打造前台+中台通用提效解决方案
基于Vue3,打造前台中台通用提效解决方案download》chaoxingit.com/297/基于Vue3,打造前台中台通用提效解决方案随着互联网技术的发展,前端框架的选择和应用变得越来越重要。Vue3作为当前最受欢迎的前端框架之一,具有强大的功能
韦康 韦康
1个月前
Camunda高级实战培训系列教程
Camunda高级实战培训系列教程download》itzcw.com/6863/Camunda高级实战:实现灵活的业务流程管理Camunda是一个流程引擎和业务流程管理平台,它可以帮助企业设计、执行和监控业务流程。本文将介绍如何在实际项目中利用Camun
光之守卫 光之守卫
1个月前
Camunda高级实战培训系列教程
Camunda高级实战培训系列教程download》itzcw.com/6863/Camunda高级实战:实现灵活的业务流程管理Camunda是一个流程引擎和业务流程管理平台,它可以帮助企业设计、执行和监控业务流程。本文将介绍如何在实际项目中利用Camun
曼成 曼成
6个月前
简化业务流程——通知短信API在企业中的应用
简化业务流程——通知短信API在企业中的应用
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k