Skip to content

Commit 6a1819c

Browse files
committed
README: update Spring example to support Spring 6.2+
1 parent 12384de commit 6a1819c

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
![Maven Central Version](https://img.shields.io/maven-central/v/net.sizovs/pipelinr)
66
[![libs.tech recommends](https://libs.tech/project/169682577/badge.svg)](https://libs.tech/project/169682577/pipelinr)
77

8-
98
> **PipelinR** is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your awesome Java app.
109
1110
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.
1211

1312
⚡ Tested and works with plain Java, Kotlin, Spring, and Jakarta EE.
1413

1514
## Table of contents
15+
1616
- [How to use](#how-to-use)
1717
- [Commands](#commands)
1818
- [Handlers](#handlers)
@@ -93,11 +93,11 @@ class Pong implements Command.Handler<Ping, String> {
9393
```
9494

9595
## Pipeline
96+
9697
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.
9798

9899
To construct a `Pipeline`, create an instance of `Pipelinr` and provide a list of command handlers:
99100

100-
101101
```java
102102
Pipeline pipeline = new Pipelinr()
103103
.with(
@@ -243,6 +243,7 @@ new Ping().send(pipeline);
243243
```
244244

245245
💡 Remember to provide notification handlers to PipelinR:
246+
246247
```java
247248
new Pipelinr()
248249
.with(
@@ -269,19 +270,22 @@ new Pipelinr().with(() -> Stream.of(new Transactional()))
269270
```
270271

271272
### Notification handling strategies
273+
272274
The default implementation loops through the notification handlers and awaits each one. This ensures each handler is run after one another.
273275

274276
Depending on your use-case for sending notifications, you might need a different strategy for handling the notifications, such running handlers in parallel.
275277

276278
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.
283286

284287
You can override default strategy via:
288+
285289
```java
286290
new Pipelinr().with(new ContinueOnException());
287291
```
@@ -298,10 +302,10 @@ class PipelinrConfiguration {
298302

299303
@Bean
300304
Pipeline pipeline(ObjectProvider<Command.Handler> commandHandlers, ObjectProvider<Notification.Handler> notificationHandlers, ObjectProvider<Command.Middleware> middlewares) {
301-
return new Pipelinr()
302-
.with(commandHandlers::stream)
303-
.with(notificationHandlers::stream)
304-
.with(middlewares::orderedStream);
305+
return new Pipelinr()
306+
.with(() -> commandHandlers.stream())
307+
.with(() -> notificationHandlers.stream())
308+
.with(() -> middlewares.orderedStream());
305309
}
306310
}
307311
```
@@ -322,7 +326,6 @@ class WaveBack implements Command.Handler<Wave, String> {
322326
}
323327
```
324328

325-
326329
Optionally, define `Order`-ed middlewares:
327330

328331
```java
@@ -407,13 +410,14 @@ Sending `AsyncPing` to the pipeline returns `CompletableFuture`:
407410
CompletableFuture<String> okInFuture = new Ping().execute(pipeline);
408411
```
409412

410-
411413
## How to contribute
414+
412415
Just fork the repo and send us a pull request.
413416

414417
## Alternatives
415-
- [MediatR](https://github.com/jbogard/MediatR) – Simple, unambitious mediator implementation in .NET
416418

419+
- [MediatR](https://github.com/jbogard/MediatR) – Simple, unambitious mediator implementation in .NET
417420

418421
## Contributors
422+
419423
- Eduards Sizovs: [Blog](https://sizovs.net)[Twitter](https://twitter.com/eduardsi)[GitHub](https://github.com/sizovs)

0 commit comments

Comments
 (0)