parent
82ae73e80f
commit
0f1af2a954
|
@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filtering.Tests", "tests\Fi
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "tests\Common\Common.csproj", "{22F31937-7F3E-47B2-A8BB-DC2B889BA228}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acting", "src\Acting\Acting.csproj", "{17C5E2AA-8B3B-4880-AA6C-BB6A99461559}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acting.Tests", "tests\Acting\Acting.Tests.csproj", "{3D87A741-B497-4225-9DCA-0C11DBEA6FF4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -58,6 +62,14 @@ Global
|
|||
{22F31937-7F3E-47B2-A8BB-DC2B889BA228}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{22F31937-7F3E-47B2-A8BB-DC2B889BA228}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{22F31937-7F3E-47B2-A8BB-DC2B889BA228}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{17C5E2AA-8B3B-4880-AA6C-BB6A99461559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{17C5E2AA-8B3B-4880-AA6C-BB6A99461559}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{17C5E2AA-8B3B-4880-AA6C-BB6A99461559}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{17C5E2AA-8B3B-4880-AA6C-BB6A99461559}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3D87A741-B497-4225-9DCA-0C11DBEA6FF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3D87A741-B497-4225-9DCA-0C11DBEA6FF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3D87A741-B497-4225-9DCA-0C11DBEA6FF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3D87A741-B497-4225-9DCA-0C11DBEA6FF4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{FF4D591C-67FE-4E8E-AD73-D13465D6DB44} = {C9061001-B6D0-49F8-AA95-5D421E96DDA2}
|
||||
|
@ -67,5 +79,7 @@ Global
|
|||
{A24F6F20-3B62-44E3-888D-CBCD3F29C477} = {C9061001-B6D0-49F8-AA95-5D421E96DDA2}
|
||||
{308F1FFC-191C-4C33-900A-0567413BE1BB} = {A6E6BB70-923B-4A64-A5E6-8AFE18B535AA}
|
||||
{22F31937-7F3E-47B2-A8BB-DC2B889BA228} = {A6E6BB70-923B-4A64-A5E6-8AFE18B535AA}
|
||||
{17C5E2AA-8B3B-4880-AA6C-BB6A99461559} = {C9061001-B6D0-49F8-AA95-5D421E96DDA2}
|
||||
{3D87A741-B497-4225-9DCA-0C11DBEA6FF4} = {A6E6BB70-923B-4A64-A5E6-8AFE18B535AA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
40
README.md
40
README.md
|
@ -1,8 +1,44 @@
|
|||
# ProSol.Messaging
|
||||
|
||||
Implements a message broker with ability to build a pipeline of listeners.
|
||||
The project consists of:
|
||||
|
||||
For example, let's make a pipeline which detects future and past dates:
|
||||
|
||||
Add package:
|
||||
```sh
|
||||
dotnet add package ProSol.Messaging --version 4.0
|
||||
```
|
||||
|
||||
```csharp
|
||||
using ProSol.Messaging;
|
||||
using ProSol.Messaging.Filtering;
|
||||
using ProSol.Messaging.Acting;
|
||||
|
||||
var provider = new PipelineMessagePublisher<DateTime>();
|
||||
|
||||
provider
|
||||
.Endpoint(x => x >= DateTime.Now)
|
||||
.Act(x => Console.WriteLine($"Future: {x}"));
|
||||
|
||||
provider
|
||||
.Act(x => Console.WriteLine($"Past: {x}"));
|
||||
|
||||
provider.Publish(DateTime.Today.AddDays(1));
|
||||
provider.Publish(DateTime.Today.AddDays(-1));
|
||||
```
|
||||
|
||||
Try this and you will see two messages in the console, with dates, depending on your current time:
|
||||
```
|
||||
Future: ...
|
||||
Past: ...
|
||||
```
|
||||
|
||||
That's it! It's basically a pipeline builder for dispatching the messages.
|
||||
|
||||
There are some more extension methods for dispatching, you may find there:
|
||||
- observer-related interfaces [here](/src/Contracts/).
|
||||
- `PipelineMessagePublisher` [here](/src/Publishers/PipelineMessagePublisher.cs).
|
||||
- [Translating](/docs/Translating.md) for messages.
|
||||
- [Filtering](/docs/Filtering.md) for messages.
|
||||
- [Filtering](/docs/Filtering.md) for messages.
|
||||
|
||||
Happy coding!
|
|
@ -5,6 +5,7 @@
|
|||
<ProjectReference Include="..\src\Publishers\Publishers.csproj" />
|
||||
<ProjectReference Include="..\src\Translating\Translating.csproj" />
|
||||
<ProjectReference Include="..\src\Filtering\Filtering.csproj" />
|
||||
<ProjectReference Include="..\src\Acting\Acting.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<metadata>
|
||||
<id>ProSol.Messaging</id>
|
||||
<title>ProSol.Messaging</title>
|
||||
<version>4.0.0-rc.9.0</version>
|
||||
<version>4.0.0</version>
|
||||
<authors>Alex Kozachenko</authors>
|
||||
<owners>Alex Kozachenko</owners>
|
||||
<projectUrl> https://git.disroot.org/alexenko/ProSol.Messaging </projectUrl>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\Translating\Translating.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,13 @@
|
|||
using ProSol.Messaging.Translating;
|
||||
|
||||
namespace ProSol.Messaging.Acting;
|
||||
|
||||
internal class ActionSubscription<TMessage>(Action<TMessage> action)
|
||||
: TranslatorBase<TMessage, TMessage>
|
||||
{
|
||||
protected override TMessage ConvertMessage(TMessage message)
|
||||
{
|
||||
action(message);
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
namespace ProSol.Messaging.Acting;
|
||||
|
||||
public static class IPublisherFluentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Filters a messages from a publisher.
|
||||
/// </summary>
|
||||
public static IPublisher<TMessage> Act<TMessage>(
|
||||
this IPublisher<TMessage> publisher,
|
||||
Action<TMessage> action)
|
||||
{
|
||||
var subscription = new ActionSubscription<TMessage>(action);
|
||||
var unsubscriber = publisher.Subscribe(subscription);
|
||||
return subscription;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common\Common.csproj" />
|
||||
<ProjectReference Include="..\..\src\Acting\Acting.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
global using NUnit.Framework;
|
||||
global using ProSol.Messaging;
|
||||
global using ProSol.Messaging.Tests.Common;
|
|
@ -0,0 +1,30 @@
|
|||
namespace ProSol.Messaging.Acting.Tests;
|
||||
|
||||
public class ActingTests
|
||||
{
|
||||
[Test]
|
||||
public void Act_ShouldWork()
|
||||
{
|
||||
var publisher = new PipelineMessagePublisher<string>();
|
||||
var result = "";
|
||||
publisher.Act(x => result = x);
|
||||
|
||||
publisher.Publish("Test");
|
||||
|
||||
Assert.That(result, Is.EqualTo("Test"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Act_ShouldWork_2()
|
||||
{
|
||||
var publisher = new PipelineMessagePublisher<string>();
|
||||
var result = "";
|
||||
publisher
|
||||
.Act(x => result+= x)
|
||||
.Act(x => result+= x);
|
||||
|
||||
publisher.Publish("Test");
|
||||
|
||||
Assert.That(result, Is.EqualTo("TestTest"));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace ProSol.Messaging.Tests.Common;
|
||||
namespace ProSol.Messaging.Tests.Common;
|
||||
|
||||
public class TestPublisher<TMessage>(IEnumerable<TMessage> messages) : IPublisher<TMessage>
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using ProSol.Messaging.Translating;
|
||||
|
||||
namespace Filtering.Tests;
|
||||
namespace ProSol.Messaging.Filtering.Tests;
|
||||
|
||||
public class FilteringTests
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using ProSol.Messaging.Subscriptions;
|
||||
|
||||
namespace ProSol.Messaging.Tests.Subscriptions;
|
||||
namespace ProSol.Messaging.Subscriptions.Tests;
|
||||
|
||||
public class RegularSubscriptionTests
|
||||
{
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using ProSol.Messaging.Tests.Common;
|
||||
using ProSol.Messaging.Translating;
|
||||
|
||||
namespace ProSol.Messaging.Tests;
|
||||
namespace ProSol.Messaging.Translating.Tests;
|
||||
|
||||
public class MessageTranslatorTests
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue