Subscriptions removal from docs

This commit is contained in:
Alexander Kozachenko 2023-12-08 01:07:12 +03:00
parent 4b61cf1dea
commit 4dc94d1d36
2 changed files with 0 additions and 83 deletions

View file

@ -4,6 +4,5 @@ Implements a message broker with ability to build a pipeline of listeners.
The project consists of:
- observer-related interfaces,
- A publisher (see `PipelineMessagePublisher`).
- [Subscription](/docs/Subscriptions.md) mechanics for smart subscriber triggering;
- [Translators](/docs/Translating.md) for messages.
- [Filtering](/docs/Filtering.md) for messages.

View file

@ -1,82 +0,0 @@
# ProSol.Messaging.Subscriptions
Enables a conditional subscribing for a publisher:
```csharp
publisher.Subscribe(subscriber, msg => msg.Contains("ERROR"))
```
## Demo
Let`s create a console logger for error messages.
Add the package:
```
dotnet add package ProSol.Messaging --version 4.0.0-rc.6.0
```
Include the package:
```csharp
using ProSol.Messaging;
using ProSol.Messaging.Subscriptions;
```
Now, let`s build a system, which reacts on errors:
```csharp
var publisher = new PipelineMessagePublisher<string>();
var subscriber = new DataSubscriber<string>();
publisher
.Subscribe(new Logger(), msg => msg.Contains("ERROR"))
.Subscribe(subscriber);
```
So, it's a two subscribers:
- `Logger`: writes string to Console;
- `DataSubscriber`: accumulates string in innter list.
Now, lets simulate some logs:
```csharp
string[] source = [
"quick brown fox",
"introduced an ERROR",
"so the lazy dog",
"got a message"
];
foreach (var item in source)
{
publisher.Publish(item);
}
```
> Console output:
``` introduced an ERROR ```
> subscriber.Messages:
```
"quick brown fox",
"introduced an ERROR",
"so the lazy dog",
"got a message"
```
The `Logger` is just a dummy console writer:
```csharp
public class Logger : ISubscriber<string>
{
public void OnCompleted()
{
}
public void OnNext(string message)
{
Console.WriteLine(message);
}
}
```
So, the `Logger` reacts on the `IPublisher`'s messages if only they contain an "ERROR" string, without interfering the pipeline.
Happy coding!
- [BACK](../README.md)