VL.Messaging.RabbitMQ
1.1.4
dotnet add package VL.Messaging.RabbitMQ --version 1.1.4
NuGet\Install-Package VL.Messaging.RabbitMQ -Version 1.1.4
<PackageReference Include="VL.Messaging.RabbitMQ" Version="1.1.4" />
paket add VL.Messaging.RabbitMQ --version 1.1.4
#r "nuget: VL.Messaging.RabbitMQ, 1.1.4"
// Install VL.Messaging.RabbitMQ as a Cake Addin
#addin nuget:?package=VL.Messaging.RabbitMQ&version=1.1.4
// Install VL.Messaging.RabbitMQ as a Cake Tool
#tool nuget:?package=VL.Messaging.RabbitMQ&version=1.1.4
RabbitMQ Messaging
A thin wrapper around RabbitMQ that simplifies and standardizes consuming/publishing messages.
Getting Started
Install package
VL.Messaging.RabbitMQ
dotnet add package VL.Messaging.RabbitMQ
Setup the messaging core
builder.Services.AddRabbitMQMessaging(builder.Configuration);
Setup a publisher and publish a message
// Program.cs (DI Setup) builder.Services .AddRabbitMQMessaging(builder.Configuration) .AddMessagePublisher<FooMessage>("exchange", "routing-key"); // FooMessage.cs (Create or reuse a concrete message type) public class FooMessage : Message { } // Use `IMessagePublisher<FooMessage>` and let DI provide a publisher instance publisher.PublishAsync(new FooMessage());
Setup a handler and consume messages
// Program.cs (DI Setup) builder.Services .AddRabbitMQMessaging(builder.Configuration) .AddMessageConsumer("queue", "exchange") .AddMessageHandler<FooMessage, FooMessageHandler>("routing-key"); // FooMessage.cs (Create a concrete message type) public class FooMessage : Message { } // FooMessageHandler.cs (Create a concrete message handler) public class FooMessageHandler : MessageHandlerBase<FooMessage> { public override Task HandleAsync(FooMessage message, CancellationToken cancellationToken = default) { // Your implementation goes here } }
FAQ
How to set the expiration time for a certain message type?
Provide
MessagePublisherOptions
with the desired expiration time to the message publisher configuration.var options = new MessagePublisherOptions { MessageExpiration = TimeSpan.FromSeconds(30) }; builder.Services .AddRabbitMQMessaging(builder.Configuration) .AddMessagePublisher<FooMessage>("exchange", "routing-key", options);
How to set specific connection settings?
A custom configuration for the RabbitMQ messaging system can be provided through the Microsoft configuration system. Here is a little example of how it's achieved with the
appsettings.json
config file.{ // Omitted for brevity "Messaging.RabbitMQ": { "ConnectionSettings": { "HostName": "foo", "Port": 8888, "Username": "bar", "Password": "baz" } } }
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. |
-
net8.0
- FakeItEasy (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- RabbitMQ.Client (>= 6.8.1)
- Squadron.Core (>= 0.18.0)
- VL.Messaging.Abstraction (>= 1.1.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.