Fermion.EventBus.RabbitMq 1.0.0

dotnet add package Fermion.EventBus.RabbitMq --version 1.0.0
                    
NuGet\Install-Package Fermion.EventBus.RabbitMq -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="Fermion.EventBus.RabbitMq" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fermion.EventBus.RabbitMq" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Fermion.EventBus.RabbitMq" />
                    
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 Fermion.EventBus.RabbitMq --version 1.0.0
                    
#r "nuget: Fermion.EventBus.RabbitMq, 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 Fermion.EventBus.RabbitMq@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=Fermion.EventBus.RabbitMq&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Fermion.EventBus.RabbitMq&version=1.0.0
                    
Install as a Cake Tool

Fermion.EventBus.RabbitMq

A robust RabbitMQ implementation of the event bus pattern for .NET applications. This package provides distributed event processing capabilities using RabbitMQ as the message broker.

Features

  • 🚀 Distributed Event Processing: Publish and subscribe to events across multiple applications
  • 🔄 Automatic Reconnection: Built-in retry mechanism for handling connection issues
  • 🔒 Persistent Connections: Reliable message delivery with persistent connections
  • 🏥 Health Checks: Built-in health monitoring for RabbitMQ connections
  • ⚙️ Flexible Configuration: Easy configuration through options pattern
  • 🔍 Detailed Logging: Comprehensive logging for debugging and monitoring
  • 🛡️ Error Handling: Robust error handling with custom exceptions

Installation

  dotnet add package Fermion.EventBus.RabbitMq

Quick Start

  1. Configure the RabbitMQ event bus in your Program.cs:
builder.Services.AddEventBusRabbitMq(options =>
{
    // Configure RabbitMQ connection
    options.Host = "localhost";
    options.Port = 5672;
    options.UserName = "guest";
    options.Password = "guest";
    
    // Configure event bus settings
    options.DefaultTopicName = "MyApplication";
    options.ConnectionRetryCount = 5;
    
    // Register event handlers
    options.AddEventHandler<UserCreatedEventHandler>();
    
    // Subscribe to events
    options.AddSubscription<UserCreatedEvent, UserCreatedEventHandler>();
});

// Configure health check endpoint
app.MapHealthChecks("/health", new HealthCheckOptions
{
    ResponseWriter = async (context, report) =>
    {
        context.Response.ContentType = "application/json";
        await context.Response.WriteAsJsonAsync(new
        {
            status = report.Status.ToString(),
            checks = report.Entries.Select(e => new
            {
                name = e.Key,
                status = e.Value.Status.ToString(),
                description = e.Value.Description,
                duration = e.Value.Duration.ToString()
            })
        });
    }
});
  1. Define your integration event:
public class UserCreatedEvent : IntegrationEvent
{
    public Guid UserId { get; }
    public string UserName { get; }

    public UserCreatedEvent(Guid userId, string userName)
    {
        UserId = userId;
        UserName = userName;
    }
}
  1. Create an event handler:
public class UserCreatedEventHandler : IIntegrationEventHandler<UserCreatedEvent>
{
    private readonly ILogger<UserCreatedEventHandler> _logger;

    public UserCreatedEventHandler(ILogger<UserCreatedEventHandler> logger)
    {
        _logger = logger;
    }

    public async Task HandleAsync(UserCreatedEvent @event)
    {
        _logger.LogInformation("User created: {UserId}, {UserName}", @event.UserId, @event.UserName);
        // Handle the event
    }
}
  1. Publish events:
public class UserController : ControllerBase
{
    private readonly IEventBus _eventBus;

    public UserController(IEventBus eventBus)
    {
        _eventBus = eventBus;
    }

    [HttpPost]
    public async Task<IActionResult> CreateUser(CreateUserRequest request)
    {
        // Create user logic...

        var @event = new UserCreatedEvent(userId, request.UserName);
        await _eventBus.PublishAsync(@event);

        return Ok();
    }
}

Configuration Options

Option Description Default Value
Host RabbitMQ host name "localhost"
Port RabbitMQ port number 5672
UserName RabbitMQ user name "guest"
Password RabbitMQ password "guest"
DefaultTopicName Default exchange name "DefaultTopic"
ConnectionRetryCount Number of connection retry attempts 5
SubscriberClientAppName Subscriber client application name Current domain name
EventNamePrefix Prefix for event names ""
EventNameSuffix Suffix for event names ""
EnableHealthCheck Enable health checks true
HealthCheckInterval Health check interval 30 seconds

Health Checks

The package includes built-in health checks for RabbitMQ connections. To enable health checks:

builder.Services.AddEventBusRabbitMq(options =>
{
    options.EnableHealthCheck = true;
    options.HealthCheckInterval = TimeSpan.FromSeconds(30);
});

Error Handling

The package provides custom exceptions for different error scenarios:

  • EventBusException: Base exception for event bus errors
  • ConnectionError: Raised when there are connection issues
  • PublishingError: Raised when event publishing fails
  • SubscriptionError: Raised when subscription operations fail

Best Practices

  1. Connection Management:

    • Use persistent connections for reliable message delivery
    • Configure appropriate retry counts for your environment
    • Monitor connection health through health checks
  2. Event Design:

    • Keep events immutable
    • Include only necessary data in events
    • Use meaningful event names
  3. Error Handling:

    • Implement proper error handling in event handlers
    • Use logging for debugging and monitoring
    • Handle connection issues gracefully
  4. Performance:

    • Configure appropriate connection retry intervals
    • Monitor message processing times
    • Use appropriate queue configurations
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 242 6/9/2025