# stepchain **Repository Path**: shiyouxu/stepchain ## Basic Information - **Project Name**: stepchain - **Description**: 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 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 50 - **Created**: 2019-08-07 - **Last Updated**: 2021-11-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # stepchain-spring-boot-starter 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。 stepchain 通用业务流程流水线处理框架。 类似于Commons Chain和Commons Pipeline这样的Java Pipeline Step Chain用于组织复杂处理流程执行的流行技术。 gitee: https://gitee.com/zengfr/stepchain github: https://github.com/zengfr/stepchain-spring-boot-starter/ [Repositories Central Sonatype Mvnrepository](https://mvnrepository.com/search?q=com.github.zengfr.project) ``` Feature: 1、支持通用业务job、services子流程无限制拆分。 2、支持业务子流程串行化、业务子流程并行化,可配置化。 3、支持Config业务子流程开启或禁用、配置串行或并行以及并行数的统一配置。 4、支持业务流程以及子流程任意无限嵌套。 5、支持配置中心、缓存、统一数据接口、redis、Es、日志Trace等。 6、支持条件分支if/else、switch、loop子流程. 备注:只开源了通用部分(不影响使用),去除了有关框架组件包括:配置中心、缓存中心、数据接口以及业务相关DataMiddle等部分API。 ``` ``` Update Log更新日志: 0.0.6 add IConditionSelector \IConditionValidator\IConditionLoopProcessor 条件分支if/else、switch、loop子流程. ``` ``` Maven Dependency: Maven(Not Use Spring Boot): com.github.zengfr.project stepchain 0.0.6 Maven(Use Spring Boot): com.github.zengfr.project stepchain-spring-boot-starter 0.0.6 Gradle: compile group: 'com.github.zengfr.project', name: 'stepchain', version: '0.0.5' compile group: 'com.github.zengfr.project', name: 'stepchain-spring-boot-starter', version: '0.0.5' ``` interface Pipeline ChainBuilder StepBuilder Step Chain [javadoc api文档](https://oss.sonatype.org/service/local/repositories/releases/archive/com/github/zengfr/project/stepchain/0.0.5/stepchain-0.0.5-javadoc.jar/!/index.html) ![stepchain-uml-class](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/zengfr-stepchain.jpg?raw=true) ```java public interface Step extends StepProcessor { void put(StepProcessor processor); void put(StepProcessor... processorArray); void put(Collection> processors); void put(Processor processor); void put(Processor... processorArray); void put(Chain chain); void put(Chain... processorArray); void put(Function func); void put(Function... processorArray); } public interface Chain extends Processor { Chain next(Processor process); Chain next(Function func); } public interface ChainBuilder { Chain createChain(Function func); Chain createChain(Processor processor); Chain createChain(Processor processor1, Processor processor2); } public interface StepBuilder { Step createStep(); Step createStep(int parallelCount); Step createStep(String parallelCountConfigName); } ``` [StepChainSpringBootTest.java](https://github.com/zengfr/stepchain-spring-boot-starter/blob/master/stepchain-spring-boot-starter/src/test/java/com/github/zengfr/project/stepchain/test/StepChainSpringBootTest.java) [PipelineTest.java](https://github.com/zengfr/stepchain-spring-boot-starter/blob/master/stepchain/src/main/java/com/github/zengfr/project/stepchain/test/PipelineTest.java)
Demo&Test you can use AbstractProcessor AbstractStepProcessor ```java import com.github.zengfr.project.stepchain abstract class AbstractProcessor implements Processor{} abstract class AbstractStepProcessor extends AbstractProcessor implements StepProcessor{} ``` ```java 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 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, Boolean> func = (context) -> { if (context.context == null) context.context = 1; context.context += 1; return true; }; UnaryContext context = ContextBuilder.createUnaryContext(); IStep> step = pipeline.createStep(); IStep> step2 = pipeline.createStep(); IChain, Boolean> c2 = pipeline.createChain(func); // c2.next(func); step2.put(c2); step2.put(step); step2.put(func); step2.process(context); System.out.println(context.context); } public static void testPipeline3(IPipeline pipeline) throws Exception { IConditionSelector selector = null; IConditionValidator validator = null; IProcessor processor = null; IProcessor first = null; IProcessor second = null; IConditionSelectorProcessor p3 = pipeline.createProcessor(validator, first, second); IConditionLoopProcessor p2 = pipeline.createProcessor(validator, processor); IConditionSelectorProcessor p1 = pipeline.createProcessor(selector); } ``` ```java @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-uml-class](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/zengfr-stepchain.jpg?raw=true) ![stepchain-javadoc](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/stepchain-javadoc.PNG?raw=true) ![stepchain-javadoc](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/chain.jpg?raw=true) ![stepchain-javadoc](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/step.jpg?raw=true) ![stepchain-javadoc](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/processor.jpg?raw=true) ![stepchain-javadoc](https://github.com/zengfr/stepchain/blob/master/stepchain/src/main/resources/pipeline.jpg?raw=true)