In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "what is the role of the stepchain framework", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the function of stepchain framework"?
Stepchain general business process pipeline processing framework.
Java Pipeline Step Chain, such as Commons Chain and Commons Pipeline, are popular techniques for organizing the execution of complex processing processes.
Feature:1, support for general business job, and unlimited split of services sub-processes. 2. Support business sub-process serialization, business sub-process parallelization and configurability. 3. Support Config business sub-process to enable or disable, configure serial or parallel and parallel number of unified configuration. 4. Support any unlimited nesting of business processes and sub-processes. 5. Support configuration center, cache, unified data interface, redis, Es, log Trace, etc. 6, support parallel branches, support conditional branches if/else, switch, loop sub-processes. 7, support Processor timing scheduling FixedRate, FixedDelay. Note: only open source the general part (does not affect the use), excluding the relevant framework components including: configuration center, cache center, data interface and business-related DataMiddle and other parts of API. Maven Dependency:Maven (Not Use Spring Boot): com.github.zengfr.project stepchain 0.0.7Maven (Use Spring Boot): com.github.zengfr.project stepchain-spring-boot-starter 0.0.7Gradle: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. What is the central idea of StepChain? How to achieve universal? Any business logic processing is abstracted into 1\ input input 2\ processor processor 3\ output output. The results of the intermediate process are generated and combined into dataMiddle. Any business logic processing is performed using multiple processor combinations. 2. How does StepChain execute multiple processor in parallel and serial? Answer: serial step=pipeline.createStep (); step.put (processors); / / processors serial execution. Parallel step=pipeline.createStep (4); step.put (processors); / / processors 4 parallel execution at the same time. 3. How does Stepchain create processor 3.1 and implement the IProcessor interface. Using IProcessorBuilder: IProcessor createProcessor (Predicate predicate); IProcessor createProcessor (Consumer consumer); IProcessor createProcessor (Function func); 4. How does StepChain reuse and combine processor? 4.1, use IChainBuilder, IChain: 4.2, use IProcessorBuilder: IProcessor createProcessor (IProcessor first, IProcessor second); IProcessor createProcessor (IProcessor processor1, IProcessor processor2, IProcessor processor3); 5. How does StepChain reuse and combine processor according to conditions? Answer: case1, existing trueProcessor\ falseProcessor2 create validator, then 1.IConditionSelectorProcessor p3 = pipeline.createConditionValidatorProcessor (validator, trueProcessor, falseProcessor) for 2 conditional execution; case2, existing processor create validator to create circular executor, and validator terminates execution when false is returned. IConditionLoopProcessor p2 = pipeline.createConditionLoopProcessor (validator, processor); case3, existing processor create switch logic, and execute a branch branchProcessor according to the key returned by selector. If the returned key is not in the branch, execute the branch branchProcessor corresponding to the default key. IConditionSelectorProcessor p1 = pipeline.createConditionSelectorProcessor (selector); p1.setBranch (S key, IProcessor processor); p1setDefaultBranch (S key); case4, existing processor create if/else if/else logic, execute branch branchProcessor if the result returned by validator is consistent with result, and execute default branch branchProcessor if it does not return the same result. 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 Lite version only open source the generic part (without affecting usage) 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 func = (context)-> {if (context.context = = null) context.context = 1; context.context + = 1; return true }; Function 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 c2 = pipeline.createChain (func); IChain 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 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);}
At this point, I believe that you have a deeper understanding of "what is the role of the stepchain framework?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.