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" />
<PackageReference Include="TestingCommons.RabbitMq" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=TestingCommons.RabbitMq&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- Dual Operation Mode: Support for both publishing and consuming messages
- Multiple Consumer Types: Simple lambda handlers, context-aware handlers, and custom consumer classes
- Flexible Configuration: Comprehensive RabbitMQ settings including TLS, clustering, and authentication
- Connection Management: Automatic health monitoring, startup, and graceful shutdown
- MassTransit Integration: Built on top of MassTransit for robust message handling
- Individual Consumer Control:
HostReceiveEndpointHandlereturn type allows granular consumer management - Bulk Consumer Operations: Stop all consumers at once or manage them individually
- Error Handling: Access to message context for retry logic and error handling
- Testing-Optimized: Designed specifically for testing message-driven architectures
Method Return Types
ConsumeMessages<T>()methods: ReturnHostReceiveEndpointHandlefor individual consumer managementPublishMessage<T>()method: ReturnsGuidrequest ID for message trackingWaitForMessages()method: ReturnsTaskfor awaiting message processingStopConsumers()method: ReturnsTaskfor graceful shutdown of all consumersHostReceiveEndpointHandle.StopAsync()method: Async method for graceful consumer shutdown
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- MassTransit (>= 8.5.2)
- MassTransit.RabbitMQ (>= 8.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.