SimpleRabbitMQClientOutBox 1.0.3
dotnet add package SimpleRabbitMQClientOutBox --version 1.0.3
NuGet\Install-Package SimpleRabbitMQClientOutBox -Version 1.0.3
<PackageReference Include="SimpleRabbitMQClientOutBox" Version="1.0.3" />
<PackageVersion Include="SimpleRabbitMQClientOutBox" Version="1.0.3" />
<PackageReference Include="SimpleRabbitMQClientOutBox" />
paket add SimpleRabbitMQClientOutBox --version 1.0.3
#r "nuget: SimpleRabbitMQClientOutBox, 1.0.3"
#:package SimpleRabbitMQClientOutBox@1.0.3
#addin nuget:?package=SimpleRabbitMQClientOutBox&version=1.0.3
#tool nuget:?package=SimpleRabbitMQClientOutBox&version=1.0.3
SimpleRabbitMQClientOutBox
Package with a simple RabbitMQ client, with the option to use the outbox pattern.
Developed in .NET 6, it is a RabbitMQ client package, built upon the rabbitMQClient.net foundation. It provides semantic routing with the possibility of declarative configuration of various connection types, exchanges, and queues automatically. It allows registration of multiple consumers and direct producers for RabbitMQ, following the outbox pattern if needed.
Package
NuGet\Install-Package SimpleRabbitMQClientOutBox -Version 1.0.3
Usage
In your class Program.cs add this code. Principal Configuration
builder.Services
.AddSimpleRabbitMQConfiguration(builder.Configuration)
Consumer Example:
builder.Services
.AddSimpleRabbitMQConfiguration(builder.Configuration)
.AddConsumerAsync<ConsumerTestAsync>(connectionName: "ConnA", exchangeName: "my-exchange", queueName: "my-queue", prefetchCount: 10)
Producer Example (Without Outbox Patten):
builder.Services
.AddSimpleRabbitMQConfiguration(builder.Configuration)
.AddProducerAsync()
To use the direct publishing service for RabbitMQ.
IProducingMessageService
Producer Example (With Outbox Patten):
builder.Services
.AddSimpleRabbitMQConfiguration(builder.Configuration)
.AddProducerAsync(new OutBoxConfig()
{
ConnectionStringDataBase = builder.Configuration.GetConnectionString("OutBoxConnection"),
CronJobConfig = "0 0/1 * * * ?"
})
To use the indirect publishing service. Persistence message in DataBase
IProducingOutBoxService
It is crucial to specify the connection name, which is equivalent to the 'Name' property in the 'RabbitMQConfig' object
await producer
.SetConnectionName("ConnA")
.SendAsync(Object, "test-exchange", "queue-RoutingKey");
//appssetings config
"RabbitMQConfig": [{
"HostName": "localhost",
"Port": 5672,
"Name": "ConnA" // Connection Name
}]
Appssetings Configuration
To use the component, it is necessary to provide RabbitMQ configurations, and if you wish to use the production strategy based on the OutBox pattern, you will also need to configure a connection string to the database with MySQL as the provider. Below are the configurations
"RabbitMQConfiguration": {
"LogEnabled": true,
"RabbitMQConfig": [
{
"HostName": "localhost", // required
"Port": 5672, // required
"Name": "ConnA", // required (ConnectionName) Important
"InitialConnectionRetries": 3,
"InitialConnectionRetryTimeoutMilliseconds" : 200,
"RequestedConnectionTimeout": 1,
"Exchanges": [
{
"Name": "my-exchange", // required
"DeadLetterExchange": "my-exchange-dead-letter",
"Type": "direct",
"Durable": true,
"AutoDelete": false,
"DeadLetterExchangeType": "direct",
"Arguments": {"",""},
"Queues": [
{
"Name": "my-queue", // required
"RoutingKey": "queue-rk",
"Durable": false,
"Exclusive": false,
"AutoDelete": false,
"Arguments": {"",""},
}
]
}
]
}
]
}
Automatic initialization
Important!!!
app.AddInicializeSimpleRabbitMQClient();
Consumer Example
// ConsumerAsyncJsonObjectBase => Deserialize the message into an object for business processing.
// The data representation of the object is contained in the protected property 'MessageObject' with a private setter within the class.
public class ConsumerTestAsync : ConsumerAsyncJsonObjectBase<AccountMessage>
{
public ConsumerTestAsync(ILoggingService loggingService,
IRabbitMQFactory rabbitMQFactory,
IOptions<RabbitMQConfiguration> rabbitMQConfig
, string connectionName
, string exchangeName
, string queueName
, ushort prefetchCount = 0) : base(loggingService, rabbitMQFactory, rabbitMQConfig, connectionName, exchangeName, queueName, prefetchCount)
{
}
protected override Task HandleMessageClientAsync(BasicDeliverEventArgs message, CancellationToken cancellationToken)
{
_loggingService.LogInformation(MessageObject.Id.ToString());
return Task.CompletedTask;
}
}
// ConsumerAsyncBase => Get message String
public class ConsumerTestAsync : ConsumerAsyncBase
{
public ConsumerTestAsync(ILoggingService loggingService,
IRabbitMQFactory rabbitMQFactory,
IOptions<RabbitMQConfiguration> rabbitMQConfig
, string connectionName
, string exchangeName
, string queueName
, ushort prefetchCount = 0) : base(loggingService, rabbitMQFactory, rabbitMQConfig, connectionName, exchangeName, queueName, prefetchCount)
{
}
protected override Task HandleMessageClientAsync(BasicDeliverEventArgs message, CancellationToken cancellationToken)
{
var _messageString = message.GetMessage();
return Task.CompletedTask;
}
}
For Data Base OutBox Usage
The database connection provider is MySQL. To find the script for creating the database and table, please check the 'script.txt' file in the root of the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.EntityFrameworkCore (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- Pomelo.EntityFrameworkCore.MySql (>= 6.0.0)
- Quartz.Extensions.DependencyInjection (>= 3.7.0)
- Quartz.Extensions.Hosting (>= 3.7.0)
- RabbitMQ.Client (>= 6.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.