EasyNetQSubscriberLib 1.0.0
dotnet add package EasyNetQSubscriberLib --version 1.0.0
NuGet\Install-Package EasyNetQSubscriberLib -Version 1.0.0
<PackageReference Include="EasyNetQSubscriberLib" Version="1.0.0" />
<PackageVersion Include="EasyNetQSubscriberLib" Version="1.0.0" />
<PackageReference Include="EasyNetQSubscriberLib" />
paket add EasyNetQSubscriberLib --version 1.0.0
#r "nuget: EasyNetQSubscriberLib, 1.0.0"
#:package EasyNetQSubscriberLib@1.0.0
#addin nuget:?package=EasyNetQSubscriberLib&version=1.0.0
#tool nuget:?package=EasyNetQSubscriberLib&version=1.0.0
EasyNetQSubscriberLib
EasyNetQSubscriberLib is a lightweight .NET library that provides a minimal abstraction for managing EasyNetQ subscribers. It defines a simple ISubscriber interface along with a SubscriberBackgroundService that automatically iterates over all registered subscriber implementations and invokes their Subscribe() method. This design allows each consuming project to implement its own subscription logic using EasyNetQ directly without hiding any underlying functionality.
Features
- Minimal Abstraction: Only provides the
ISubscriberinterface and a background service. - Flexible Integration: Consumers implement their own subscription logic using EasyNetQ (e.g., using
RespondAsyncorSubscribeAsync). - Background Service: Automatically calls the
Subscribe()method on all implementations ofISubscriberduring startup. - Logging Support: Integrated with
ILoggerfor consistent logging. - Cross-Platform: Compatible with .NET 8.0 and Linux x64.
Requirements
Installation
Install the package via NuGet:
dotnet add package EasyNetQSubscriberLib --version 1.0.0
Usage
- Implement the ISubscriber Interface In your consumer project, implement the ISubscriber interface according to your messaging needs. For example, to implement a responder using
EasyNetQ: using System.Threading.Tasks; using EasyNetQ; using EasyNetQSubscriberLib.Messaging; using MyProject.Models; // Your custom models
namespace MyProject.Subscribers { public class MyResponder : ISubscriber { private readonly IBus _bus;
public MyResponder(IBus bus)
{
_bus = bus;
}
public void Subscribe()
{
// Example using RespondAsync for a request/response pattern.
_bus.RespondAsync<MyRequest, MyResponse>(HandleRequestAsync);
}
private async Task<MyResponse> HandleRequestAsync(MyRequest request)
{
// Your custom logic to process the request.
return await Task.FromResult(new MyResponse { Success = true });
}
}
}
- Configure Dependency Injection and the Background Service In your application's startup (for example, in Program.cs), register the necessary services, your subscriber implementations, and the background service. You can use an assembly scanning tool like Scrutor to automatically register all classes that implement ISubscriber:
using EasyNetQ; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using EasyNetQSubscriberLib.Messaging;
IHost host = Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) ⇒ { // Register the EasyNetQ IBus instance services.AddSingleton<IBus>(_ ⇒ RabbitHutch.CreateBus("host=localhost"));
// Automatically register all implementations of ISubscriber using Scrutor
services.Scan(scan => scan
.FromAssemblyOf<ISubscriber>()
.AddClasses(classes => classes.AssignableTo<ISubscriber>())
.AsImplementedInterfaces()
.WithSingletonLifetime());
// Register the background service that calls Subscribe() on all ISubscriber implementations
services.AddHostedService<SubscriberBackgroundService>();
})
.Build();
await host.RunAsync();
When your application starts, the SubscriberBackgroundService will resolve all registered ISubscriber implementations, call their Subscribe() method, and execute your custom subscription logic.
Contributing Contributions are welcome! Feel free to fork the repository, open issues, or submit pull requests with improvements.
License This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Hosting (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 161 | 2/27/2025 |