Subscriptions removal from docs
This commit is contained in:
parent
4b61cf1dea
commit
4dc94d1d36
|
@ -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.
|
|
@ -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)
|
Loading…
Reference in a new issue