stepchain框架有什么作用
发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,本篇内容主要讲解"stepchain框架有什么作用",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"stepchain框架有什么作用"吧!stepchain
千家信息网最后更新 2025年02月04日stepchain框架有什么作用
本篇内容主要讲解"stepchain框架有什么作用",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"stepchain框架有什么作用"吧!
stepchain 通用业务流程流水线处理框架。
类似于Commons Chain和Commons Pipeline这样的Java Pipeline Step Chain用于组织复杂处理流程执行的流行技术。
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'
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 createProcessor(Predicate predicate); IProcessor createProcessor(Consumer consumer); IProcessor createProcessor(Function func);4、StepChain 如何复用和组合processor? 4.1、使用IChainBuilder、IChain: 4.2、使用IProcessorBuilder: IProcessor createProcessor(IProcessor first, IProcessor second); IProcessor createProcessor(IProcessor processor1, IProcessor processor2, IProcessorprocessor3);5、StepChain 如何按条件复用和组合processor?答: case1、已有trueProcessor\falseProcessor2个 创建 validator 则按条件执行2则之1.IConditionSelectorProcessor p3 = pipeline.createConditionValidatorProcessor(validator, trueProcessor, falseProcessor);case2、已有processor 创建 validator 创建循环执行体,validator 返回false时终止执行。IConditionLoopProcessor p2 = pipeline.createConditionLoopProcessor(validator, processor);case3、已有processor创建 switch 逻辑,根据selector返回的key执行某1分支branchProcessor如果返回的key不在分支中 则执行默认key对应的分支branchProcessor。IConditionSelectorProcessor p1 = pipeline.createConditionSelectorProcessor(selector);p1.setBranch(S key, IProcessor processor);p1setDefaultBranch(S key);case4、已有processor创建 if/else if/else 逻辑,根据validator返回的结果与result对比一致则执行分支branchProcessor,如果没有返回一致的 则执行默认分支branchProcessor。pipeline.createConditionValidatorSelectorProcessor();public interface IConditionValidatorSelectorProcessor extends IProcessor { void setBranch(IProcessor validator,Boolean result,IProcessor processor); void setDefaultBranch(IProcessor processor);}
public interface IStep extends IStepProcessor { void put(IStepProcessor processor); void put(IStepProcessor... processorArray); void put(Collection> processors); void put(IProcessor processor); void put(IProcessor... processorArray); void put(IChain chain); void put(IChain... processorArray); void put(Function func); void put(Function... processorArray);}public interface IChain extends IProcessor { IChain next(IProcessor process); IChain next(Function func);}public interface IChainBuilder { IChain createChain(Function func); IChain createChain(IProcessor processor); IChain createChain(IProcessor processor1, IProcessor processor2);}public interface IStepBuilder { IStep createStep(); IStep createStep(int parallelCount); IStep createStep(String parallelCountConfigName);}
StepChainSpringBootTest.java
PipelineTest.java
Demo&Test you can use AbstractProcessor AbstractStepProcessor
import com.github.zengfr.project.stepchainabstract class AbstractProcessor implements Processor{}abstract class AbstractStepProcessor extends AbstractProcessor 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); IStepstep = 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; }; Function , String> func3 = (context) -> { if (context.context == null) context.context = 1; context.context += 1; return JSON.toJSONString(context.context); }; UnaryContext context = pipeline.createContext(12345678); IStep > step = pipeline.createStep(); IStep > step2 = pipeline.createStep(); IChain , Boolean> c2 = pipeline.createChain(func); IChain , String> c3 = pipeline.createChain(func3); Function func4 = null; Function func5 = null; Function func6 = null; IChain c4 = pipeline.createChain(func4); IChain c5 = pipeline.createChain(func5); IChain c6 = pipeline.createChain(func6); IChain , 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 selector = null; IProcessor validator = null; IProcessor processor = null; IProcessor first = null; IProcessor second = null; IConditionSelectorProcessor p3 = pipeline.createConditionValidatorProcessor(validator, first, second); IConditionLoopProcessor p2 = pipeline.createConditionLoopProcessor(validator, processor); IConditionSelectorProcessor 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框架有什么作用"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
业务
流程
支持
分支
框架
处理
配置
逻辑
作用
接口
条件
部分
组合
一致
业务流程
内容
多个
数据
结果
缓存
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
湖州通信网络技术口碑推荐
广州天云网络技术有限公司
国家网络安全专业研究生
顶级网络安全师工资
海宁 网络安全四字歌
我的世界可以无限挖资源的服务器
信息化时代计算机网络安全
淄博微信公众号软件开发企业
网络技术术语sink
网络安全全域防御体系
固态服务器报错05
联想sr服务器更新微码
网络安全基本常识及其攻防方法
美服lol服务器
后台操作数据库代码
网络安全动态视频
联想服务器驱动如何备份
战争雷霆哪个服务器最不卡
三级目录如何建数据库表
算法包括指令和数据库
全局位置指纹数据库建立
潮科技卫星互联网
淘宝软件开发框架
绝地求生 服务器
巅峰坦克获取服务器失败
小森生活服务器输出率
日照龙狮互联网科技有限公司
华为v5服务器设置系统启动顺序
网络安全类投资
vue表单与数据库建立关联