TestingCommons.RabbitMq 1.0.3

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

TestingCommons.RabbitMq

The RabbitMq project provides a comprehensive client for RabbitMQ message broker operations. It supports both message publishing and consumption with flexible configuration options, making it ideal for testing message-driven architectures.

Key Components

RabbitMqClient

  • Complete message broker client supporting publish and consume operations
  • Multiple constructor overloads for different configuration scenarios
  • Automatic connection health monitoring and startup
  • Built-in consumer management and graceful shutdown

RabbitMqConfig

  • Comprehensive configuration for RabbitMQ connections
  • Support for clusters, TLS connections, and authentication
  • Configurable heartbeat intervals and redelivery settings

BusControl

  • Factory methods for creating MassTransit bus instances
  • Support for advanced receive endpoint configurations
  • Extensions for RabbitMQ-specific settings

Usage Examples

Basic Configuration

var config = new RabbitMqConfig
{
    Hostname = "localhost",
    Username = "guest",
    Password = "guest",
    VirtualHost = "/",
    Port = 5672, // or 5671 for TLS
    HeartbeatInterval = 60
};

using var client = new RabbitMqClient(config);

Publishing Messages

// Simple message publishing
var message = new OrderCreated 
{ 
    OrderId = 123, 
    Amount = 99.99m, 
    CreatedAt = DateTime.UtcNow 
};

var requestId = client.PublishMessage(message);
Console.WriteLine($"Published message with ID: {requestId}");

// Publishing with redelivery count
var retryRequestId = client.PublishMessage(message, redeliveryCount: 2);

Simple Message Handler

var config = new RabbitMqConfig
{
    Hostname = "localhost",
    Username = "guest",
    Password = "guest",
    VirtualHost = "/"
};

using var client = new RabbitMqClient(config);

// Simple message consumption with lambda
var handle = client.ConsumeMessages<MyMessage>("my-queue", async message =>
{
    Console.WriteLine($"Received: {message.Content}");
    // Process the message
});

// Keep the consumer running
await client.WaitForMessages(TimeSpan.FromMinutes(5));

// Stop the specific consumer when done
await handle.StopAsync();

Context-Aware Message Handler

// Access to the full consume context (headers, message properties, etc.)
var handle = client.ConsumeMessages<MyMessage>("my-queue", async (message, context) =>
{
    Console.WriteLine($"Received: {message.Content}");
    Console.WriteLine($"Message ID: {context.MessageId}");
    Console.WriteLine($"Request ID: {context.RequestId}");
    
    // Access headers
    if (context.Headers.TryGetHeader("CustomHeader", out var headerValue))
    {
        Console.WriteLine($"Custom Header: {headerValue}");
    }
});

Key Features

  1. Dual Operation Mode: Support for both publishing and consuming messages
  2. Multiple Consumer Types: Simple lambda handlers, context-aware handlers, and custom consumer classes
  3. Flexible Configuration: Comprehensive RabbitMQ settings including TLS, clustering, and authentication
  4. Connection Management: Automatic health monitoring, startup, and graceful shutdown
  5. MassTransit Integration: Built on top of MassTransit for robust message handling
  6. Individual Consumer Control: HostReceiveEndpointHandle return type allows granular consumer management
  7. Bulk Consumer Operations: Stop all consumers at once or manage them individually
  8. Error Handling: Access to message context for retry logic and error handling
  9. Testing-Optimized: Designed specifically for testing message-driven architectures

Method Return Types

  • ConsumeMessages<T>() methods: Return HostReceiveEndpointHandle for individual consumer management
  • PublishMessage<T>() method: Returns Guid request ID for message tracking
  • WaitForMessages() method: Returns Task for awaiting message processing
  • StopConsumers() method: Returns Task for graceful shutdown of all consumers
  • HostReceiveEndpointHandle.StopAsync() method: Async method for graceful consumer shutdown
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.3 196 8/9/2025
1.0.2 187 8/9/2025
1.0.1 164 8/9/2025
1.0.0 150 6/28/2025
0.1.1 171 8/9/2025