EasyNetQSubscriberLib 1.0.0

dotnet add package EasyNetQSubscriberLib --version 1.0.0
                    
NuGet\Install-Package EasyNetQSubscriberLib -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyNetQSubscriberLib" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyNetQSubscriberLib" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EasyNetQSubscriberLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyNetQSubscriberLib --version 1.0.0
                    
#r "nuget: EasyNetQSubscriberLib, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EasyNetQSubscriberLib@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyNetQSubscriberLib&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EasyNetQSubscriberLib&version=1.0.0
                    
Install as a Cake Tool

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 ISubscriber interface and a background service.
  • Flexible Integration: Consumers implement their own subscription logic using EasyNetQ (e.g., using RespondAsync or SubscribeAsync).
  • Background Service: Automatically calls the Subscribe() method on all implementations of ISubscriber during startup.
  • Logging Support: Integrated with ILogger for 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

  1. 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 });
    }
}

}

  1. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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