SimpleRabbitMQClientOutBox 1.0.3

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

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 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. 
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 237 10/3/2023
1.0.2 204 10/3/2023
1.0.1 204 10/3/2023