135-1821-9792

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'

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 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, IProcessor processor3);

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.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精简版 只开源了通用部分(不影响使用)
	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;

		};
		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框架有什么作用stepchain框架有什么作用  stepchain框架有什么作用

到此,相信大家对“stepchain框架有什么作用”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


网站名称:stepchain框架有什么作用
当前地址:
http://kswsj.com/article/johcge.html

  • 成都网站建设
    成都网站建设