You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **PipelinR** is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your awesome Java app.
10
9
11
10
PipelinR has been battle-proven on production as a service layer for some cool FinTech apps. PipelinR has helped teams switch from giant service classes handling all use cases to small handlers, each following the single responsibility principle. It's similar to a popular [MediatR](https://github.com/jbogard/MediatR) .NET library.
12
11
13
12
⚡ Tested and works with plain Java, Kotlin, Spring, and Jakarta EE.
14
13
15
14
## Table of contents
15
+
16
16
-[How to use](#how-to-use)
17
17
-[Commands](#commands)
18
18
-[Handlers](#handlers)
@@ -93,11 +93,11 @@ class Pong implements Command.Handler<Ping, String> {
93
93
```
94
94
95
95
## Pipeline
96
+
96
97
A **pipeline** mediates between commands and handlers. You send commands to the pipeline. When the pipeline receives a command, it sends the command through a sequence of middlewares and finally invokes the matching command handler. `Pipelinr` is a default implementation of `Pipeline` interface.
97
98
98
99
To construct a `Pipeline`, create an instance of `Pipelinr` and provide a list of command handlers:
99
100
100
-
101
101
```java
102
102
Pipeline pipeline =newPipelinr()
103
103
.with(
@@ -243,6 +243,7 @@ new Ping().send(pipeline);
243
243
```
244
244
245
245
💡 Remember to provide notification handlers to PipelinR:
246
+
246
247
```java
247
248
newPipelinr()
248
249
.with(
@@ -269,19 +270,22 @@ new Pipelinr().with(() -> Stream.of(new Transactional()))
269
270
```
270
271
271
272
### Notification handling strategies
273
+
272
274
The default implementation loops through the notification handlers and awaits each one. This ensures each handler is run after one another.
273
275
274
276
Depending on your use-case for sending notifications, you might need a different strategy for handling the notifications, such running handlers in parallel.
275
277
276
278
PipelinR supports the following strategies:
277
-
*`an.awesome.pipelinr.StopOnException` runs each notification handler after one another; returns when all handlers are finished or an exception has been thrown; in case of an exception, any handlers after that will not be run; **this is a default strategy**.
278
-
*`an.awesome.pipelinr.ContinueOnException` runs each notification handler after one another; returns when all handlers are finished; in case of any exception(s), they will be captured in an AggregateException.
279
-
*`an.awesome.pipelinr.Async` runs all notification handlers asynchronously; returns when all handlers are finished; in case of any exception(s), they will be captured in an AggregateException.
280
-
*`an.awesome.pipelinr.ParallelNoWait` runs each notification handler in a thread pool; returns immediately and does not wait for any handlers to finish; cannot capture any exceptions.
281
-
*`an.awesome.pipelinr.ParallelWhenAny` runs each notification handler in a thread pool; returns when any thread (handler) is finished; all exceptions that happened before returning are captured in an AggregateException.
282
-
*`an.awesome.pipelinr.ParallelWhenAll` runs each notification handler in a thread pool; returns when all threads (handlers) are finished; in case of any exception(s), they are captured in an AggregateException.
279
+
280
+
-`an.awesome.pipelinr.StopOnException` runs each notification handler after one another; returns when all handlers are finished or an exception has been thrown; in case of an exception, any handlers after that will not be run; **this is a default strategy**.
281
+
-`an.awesome.pipelinr.ContinueOnException` runs each notification handler after one another; returns when all handlers are finished; in case of any exception(s), they will be captured in an AggregateException.
282
+
-`an.awesome.pipelinr.Async` runs all notification handlers asynchronously; returns when all handlers are finished; in case of any exception(s), they will be captured in an AggregateException.
283
+
-`an.awesome.pipelinr.ParallelNoWait` runs each notification handler in a thread pool; returns immediately and does not wait for any handlers to finish; cannot capture any exceptions.
284
+
-`an.awesome.pipelinr.ParallelWhenAny` runs each notification handler in a thread pool; returns when any thread (handler) is finished; all exceptions that happened before returning are captured in an AggregateException.
285
+
-`an.awesome.pipelinr.ParallelWhenAll` runs each notification handler in a thread pool; returns when all threads (handlers) are finished; in case of any exception(s), they are captured in an AggregateException.
283
286
284
287
You can override default strategy via:
288
+
285
289
```java
286
290
newPipelinr().with(newContinueOnException());
287
291
```
@@ -290,18 +294,18 @@ new Pipelinr().with(new ContinueOnException());
290
294
291
295
PipelinR works well with Spring and Spring Boot.
292
296
293
-
Start by configuring a `Pipeline`. Create an instance of `Pipelinr` and inject all command handlers and **ordered** middlewares via the constructor:
297
+
Start by configuring a `Pipeline`. Create an instance of `Pipelinr` and inject all command handlers and **ordered** middlewares:
0 commit comments