- Notifications
You must be signed in to change notification settings - Fork1
Boru is a pipeline solution
License
Trendyol/boru
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
boru is a pipeline implementation in kotlin with native coroutine support and custom dsl.
Supports chaining pipeline steps with conditions and branches.
Inspired by@oguzhaneren's C# implementation
<dependency> <groupId>com.trendyol</groupId> <artifactId>boru</artifactId> <version>1.0.0</version></dependency>
Define a context implementing PipelineContext. In this case a simple context that sets and gets a text field
interfacePipelineContext {val items:Map<Any,Any>}classTestDataContext :PipelineContext {overrideval items:MutableMap<Any,Any>=mutableMapOf()var intValue:Int=0var text:String? get()= items.getOrDefault("Text",null).toString() set(value) { items["Text"]= value!! }}
Implement a pipeline step using TestDataContext
classTestWriterStep(privatevaltext:String,) : PipelineStep<TestDataContext> {overridesuspendfunexecute(context:TestDataContext,next:PipelineStepDelegate<TestDataContext>) { context.text= text next(context) }}
funcompose() {val pipeline=PipelineBuilder<TestDataContext>() .usePipelineStep(TestWriterStep("hello")) .build()val context=TestDataContext()}
You can also use lambda functions without defining a pipeline step
funcompose() {val pipeline=PipelineBuilder<TestDataContext>() .use { context:TestDataContext, next:suspend ()->Unit-> context.text="hello" next() } .build()val context=TestDataContext()}
Or use built-in dsl
funcompose() {val pipeline= pipelineBuilder<TestDataContext> { use { testDataContext:TestDataContext, next:suspend ()->Unit-> context.text="Hello World" next() } }}
You can also use conditions when executing steps or branch using map operation
funcompose() {val pipeline= pipelineBuilder<TestDataContext> { usePipelineStepWhen(TestWriterStep("Hello World")) { it.text=="ExecuteStep" } }}
Mapping allows you to group multiple steps under one condition.
funcomposeMapping() {val pipeline= pipelineBuilder<TestDataContext> { map({ it.intValue<3 }) { usePipelineStep(TestWriterStep("one")) usePipelineStep(TestWriterStep("two")) } map({ it.intValue==3 }) { usePipelineStep(TestWriterStep("three")) } }}
You can check out otherexamples
About
Boru is a pipeline solution
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors2
Uh oh!
There was an error while loading.Please reload this page.