歡迎您光臨本站 註冊首頁

stepchain 0.0.6 發布,新增支持條件子流程

←手機掃碼閱讀     admin @ 2019-08-07 , reply:0

Update Log更新日誌:

0.0.6 add IConditionSelector IConditionValidator\IConditionLoopProcessor 條件分支if/else、swith、loop子流程.

gitee: https://gitee.com/zengfr/stepchain

github: https://github.com/zengfr/stepchain-spring-boot-starter/

Repositories Central Sonatype Mvnrepository


Feature:
1、支持通用業務job、services子流程無限制拆分。
2、支持業務子流程串列化、業務子流程并行化,可配置化。
3、支持Config業務子流程開啟或禁用、配置串列或并行以及并行數的統一配置。
4、支持業務流程以及子流程任意無限嵌套。
5、支持配置中心、緩存、統一數據介面、redis、Es、日誌Trace等。
6、支持條件分支if/else、swith、loop子流程.
備註:只開源了通用部分(不影響使用),去除了有關框架組件包括:配置中心、緩存中心、數據介面以及業務相關DataMiddle等部分API。

Maven Dependency:
Maven(Not Use Spring Boot):
<dependency>
 <groupId>com.github.zengfr.project</groupId>
 <artifactId>stepchain</artifactId>
 <version>0.0.6</version>
<dependency>
Maven(Use Spring Boot):
<dependency>
 <groupId>com.github.zengfr.project</groupId>
 <artifactId>stepchain-spring-boot-starter</artifactId>
 <version>0.0.6</version>
<dependency>
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文檔 stepchain-uml-class


public interface Step<I> extends StepProcessor<I> {
	void put(StepProcessor<I> processor);

	void put(StepProcessor<I>... processorArray);

	void put(Collection<StepProcessor<I>> processors);

	void put(Processor<I, Boolean> processor);

	void put(Processor<I, Boolean>... processorArray);

	void put(Chain<I, Boolean> chain);

	void put(Chain<I, Boolean>... processorArray);

	void put(Function<I, Boolean> func);

	void put(Function<I, Boolean>... processorArray);
}
public interface Chain<A, B> extends Processor<A, B> {
	<C> Chain<A, C> next(Processor<B, C> process);

	<C> Chain<A, C> next(Function<B, C> func);
}
public interface ChainBuilder {
	<A, B> Chain<A, B> createChain(Function<A, B> func);

	<A, B> Chain<A, B> createChain(Processor<A, B> processor);

	<A, B, C> Chain<A, C> createChain(Processor<A, B> processor1, Processor<B, C> processor2);
}
public interface StepBuilder {
	<T> Step<T> createStep();

	<T> Step<T> createStep(int parallelCount);

	<T> Step<T> createStep(String parallelCountConfigName);
}

StepChainSpringBootTest.java

PipelineTest.java 
Demo&Test you can use AbstractProcessor AbstractStepProcessor


import com.github.zengfr.project.stepchain
abstract class AbstractProcessor<I, O> implements Processor<I, O>{}
abstract class AbstractStepProcessor<A> extends AbstractProcessor<A, Boolean> implements StepProcessor<A>{}

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<SetProductContext> 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<UnaryContext<Integer>, Boolean> func = (context) -> {
		if (context.context == null)
		context.context = 1;
		context.context += 1;
		return true;

	};
	UnaryContext<Integer> context = ContextBuilder.createUnaryContext();
	IStep<UnaryContext<Integer>> step = pipeline.createStep();
	IStep<UnaryContext<Integer>> step2 = pipeline.createStep();
	IChain<UnaryContext<Integer>, 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<String, String> selector = null;
		IConditionValidator<String> validator = null;

		IProcessor<String, String> processor = null;
		IProcessor<String, String> first = null;
		IProcessor<String, String> second = null;

		IConditionSelectorProcessor<String, Boolean, String> p3 = pipeline.createProcessor(validator, first, second);
		IConditionLoopProcessor<String, String> p2 = pipeline.createProcessor(validator, processor);

		IConditionSelectorProcessor<String, String, String> p1 = pipeline.createProcessor(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-uml-classstepchain-javadocstepchain-javadoc stepchain-javadoc stepchain-javadoc stepchain-javadoc

 捐贈 


[admin ]

來源:OsChina
連結:https://www.oschina.net/news/108867/stepchain-0-0-6-released
stepchain 0.0.6 發布,新增支持條件子流程已經有108次圍觀

http://coctec.com/news/all/show-post-211796.html