重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
本篇內(nèi)容主要講解“stepchain框架有什么作用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“stepchain框架有什么作用”吧!
在網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)過程中,需要針對(duì)客戶的行業(yè)特點(diǎn)、產(chǎn)品特性、目標(biāo)受眾和市場(chǎng)情況進(jìn)行定位分析,以確定網(wǎng)站的風(fēng)格、色彩、版式、交互等方面的設(shè)計(jì)方向。創(chuàng)新互聯(lián)還需要根據(jù)客戶的需求進(jìn)行功能模塊的開發(fā)和設(shè)計(jì),包括內(nèi)容管理、前臺(tái)展示、用戶權(quán)限管理、數(shù)據(jù)統(tǒng)計(jì)和安全保護(hù)等功能。
stepchain 通用業(yè)務(wù)流程流水線處理框架。
類似于Commons Chain和Commons Pipeline這樣的Java Pipeline Step Chain用于組織復(fù)雜處理流程執(zhí)行的流行技術(shù)。
Feature: 1、支持通用業(yè)務(wù)job、services子流程無限制拆分。 2、支持業(yè)務(wù)子流程串行化、業(yè)務(wù)子流程并行化,可配置化。 3、支持Config業(yè)務(wù)子流程開啟或禁用、配置串行或并行以及并行數(shù)的統(tǒng)一配置。 4、支持業(yè)務(wù)流程以及子流程任意無限嵌套。 5、支持配置中心、緩存、統(tǒng)一數(shù)據(jù)接口、redis、Es、日志Trace等。 6、支持并行分支,支持條件分支if/else、switch、loop子流程. 7、支持Processor定時(shí)調(diào)度FixedRate、FixedDelay。 備注:只開源了通用部分(不影響使用),去除了有關(guān)框架組件包括:配置中心、緩存中心、數(shù)據(jù)接口以及業(yè)務(wù)相關(guān)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、任何業(yè)務(wù)邏輯處理抽象成1\input輸入 2\ processor處理器 3\output輸出.中間過程結(jié)果產(chǎn)生和組合成dataMiddle。 1.2、任何業(yè)務(wù)邏輯處理使用多個(gè)processor組合執(zhí)行。 2、StepChain 如何并行和串行執(zhí)行多個(gè)processor? 答: 串行step=pipeline.createStep();step.put(processors);//processors串行執(zhí)行. 并行step=pipeline.createStep(4);step.put(processors);//processors同時(shí)4個(gè)并行執(zhí)行. 3、Stepchain 如何創(chuàng)建processor? 3.1、實(shí)現(xiàn) IProcessor 接口。 3.2、使用IProcessorBuilder: IProcessor createProcessor(Predicate predicate); IProcessor createProcessor(Consumer consumer); IProcessor createProcessor(Function func); 4、StepChain 如何復(fù)用和組合processor? 4.1、使用IChainBuilder、IChain: 4.2、使用IProcessorBuilder: IProcessor createProcessor(IProcessor first, IProcessor second); IProcessor createProcessor(IProcessor processor1, IProcessor processor2, IProcessorprocessor3); 5、StepChain 如何按條件復(fù)用和組合processor? 答: case1、已有trueProcessor\falseProcessor2個(gè) 創(chuàng)建 validator 則按條件執(zhí)行2則之1. IConditionSelectorProcessor p3 = pipeline.createConditionValidatorProcessor(validator, trueProcessor, falseProcessor); case2、已有processor 創(chuàng)建 validator 創(chuàng)建循環(huán)執(zhí)行體,validator 返回false時(shí)終止執(zhí)行。 IConditionLoopProcessor p2 = pipeline.createConditionLoopProcessor(validator, processor); case3、已有processor創(chuàng)建 switch 邏輯,根據(jù)selector返回的key執(zhí)行某1分支branchProcessor如果返回的key不在分支中 則執(zhí)行默認(rèn)key對(duì)應(yīng)的分支branchProcessor。 IConditionSelectorProcessor p1 = pipeline.createConditionSelectorProcessor(selector); p1.setBranch(S key, IProcessor processor); p1setDefaultBranch(S key); case4、已有processor創(chuàng)建 if/else if/else 邏輯,根據(jù)validator返回的結(jié)果與result對(duì)比一致則執(zhí)行分支branchProcessor,如果沒有返回一致的 則執(zhí)行默認(rèn)分支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.stepchain abstract 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精簡(jiǎn)版 只開源了通用部分(不影響使用) 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); }
到此,相信大家對(duì)“stepchain框架有什么作用”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!