EzRabbitMq 0.1.2-beta001

This is a prerelease version of EzRabbitMq.
There is a newer version of this package available.
See the version list below for details.
dotnet add package EzRabbitMq --version 0.1.2-beta001
                    
NuGet\Install-Package EzRabbitMq -Version 0.1.2-beta001
                    
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="EzRabbitMq" Version="0.1.2-beta001" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EzRabbitMq" Version="0.1.2-beta001" />
                    
Directory.Packages.props
<PackageReference Include="EzRabbitMq" />
                    
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 EzRabbitMq --version 0.1.2-beta001
                    
#r "nuget: EzRabbitMq, 0.1.2-beta001"
                    
#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 EzRabbitMq@0.1.2-beta001
                    
#: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=EzRabbitMq&version=0.1.2-beta001&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=EzRabbitMq&version=0.1.2-beta001&prerelease
                    
Install as a Cake Tool

EzRabbitMq

Library for .Net Core 5 simplifying the usage of rabbitMq.

Optional AppInsight consumer/ message / producer tracing.

Error handling with optional retry count.

PollyRetryPolicies on rabbitMq calls for client resiliency.

Usage

Register services :

services.AddEzRabbitMq(config); // IConfiguration

Configuration

In AppSettings.json file:

{ 
  "EzRabbitMq": {
    "HostName": "localhost",
    "UserName": "guest",
    "Password": "guest",
    "Port": 5672
  }
}

Or using environment variables :

// linux example
export EzRabbitMq__HostName="localhost"

// powershell example
$env:EzRabbitMq__HostName="localhost"

Send direct message

IProducerService producerService; // use injection to get a IProducerService
producerService.Send(new DirectProducerOptions("ROUTING KEY"), new { Example = 123 });

Send topic message

IProducerService producerService; // use injection to get a IProducerService
producerService.Send(new TopicProducerOptions("ROUTING KEY"), new { Example = 123 });

Send fanout message

IProducerService producerService; // use injection to get a IProducerService
producerService.Send(new FanoutProducerOptions(), new { Example = 123 });

Send headers message

IProducerService producerService; // use injection to get a IProducerService
var headerProducer = new HeadersProducerOptions(new()
{
    { "file-type", "jpg" },
    { "theme", "wild" }
});
producerService.Send(headerProducer, new { Example = 123 });

Listen messages using events

You can create EventMailbox mailbox instance and react to messages with the OnMessageReceived event.

// use injection to get a IMailboxService
var mailboxOptions = new DirectMailboxOptions("ROUTING KEY", "MAILBOX NAME");
var mailbox = mailboxService.Create<EventMailbox<DataSample>>(mailboxOptions, new ConsumerOptions());

mailbox.OnMessageReceived += (sender, data) => {
    // data is IMessage<DataSample>
};

Listen direct messages

// use injection to get a IMailboxService
var mailboxOptions = new DirectMailboxOptions("ROUTING KEY", "MAILBOX NAME");
var mailbox = mailboxService.Create<EventMailbox<DataSample>>(mailboxOptions, new ConsumerOptions());

Listen topic messages

// use injection to get a IMailboxService
var mailboxOptions = new TopicMailboxOptions("ROOT.SECTOR-A.*", "MAILBOX NAME");
var mailbox = mailboxService.Create<EventMailbox<DataSample>>(mailboxOptions, new ConsumerOptions());

Listen fanout messages

// use injection to get a IMailboxService
var mailboxOptions = new FanoutMailboxOptions("MAILBOX NAME");
var mailbox = mailboxService.Create<EventMailbox<DataSample>>(mailboxOptions, new ConsumerOptions());

Listen headers messages

// use injection to get a IMailboxService
var converterToGifMailboxOptions = new HeadersMailboxOptions(new()
{
    { "type", "jpg" },
    { "type", "png" }
}, XMatch.Any, "converter-to-gif");
var converterToGifMailbox = mailboxService.Create<EventMailbox<DataSample>>(converterToGifMailboxOptions, new ConsumerOptions());

var thumbnailCreatorMailboxOptions = new HeadersMailboxOptions(new()
{
    { "type", "gif" },
    { "target", "avatar" }
}, XMatch.All, "thumbnail-creator");
var thumbnailCreatorMailbox = mailboxService.Create<EventMailbox<DataSample>>(thumbnailCreatorMailboxOptions, new ConsumerOptions());

Listen messages using implementation

Or you can implement your own Mailbox inheriting Mailbox<T>, you will have to implement the OnMessage method.

public class MyMailbox<T> : Mailbox<T>
{
    public EventMailbox(
        ILogger<MyMailbox<T>> logger,
        IMailboxOptions options,
        ISessionService session,
        ConsumerOptions consumerOptions
    ) : base(logger, options, null, session, consumerOptions)   { }

    protected override void OnMessage(IMessage<T> data)
    {
        // react to message
    }
}

// use injection to get a IMailboxService
var options = ConsumerOptions.CreateDefaultOptions;
var mailboxOptions = new DirectMailboxOptions("ROUTINg KEY", "MAILBOX NAME");
var mailbox = mailboxService.Create<MyMailbox<DataSample>>(mailboxOptions, options);

ConsumerOptions

This options can add rabbitMq arguments to enable / disable features.

ConsumerOptions default values:

RetryCount:

You can enable retry on consumer exception by using the consumerOptions object :

var options = new ConsumerOptions
{
    AutoAck = false, // AutoAck must be false to use RetryCount
    RetryCount = 3, // After 3 retry exception in the message will be reject,
};
Durable Queue :

To create a queue that will persist after server restart :

var options = new ConsumerOptions
{
    QueueDurable = true, // set durable feature on queue (need queue recreation if changed)
    QueueAutoDelete = false. // set auto delete feature on queue (need queue recreation if changed)
};
Durable Exchange :

To create a queue that will persist after server restart :

var options = new ConsumerOptions
{
    ExchangeDurable = true, // set durable feature on queue (need queue recreation if changed)
    ExchangeAutoDelete = false. // set auto delete feature on queue (need queue recreation if changed)
};
Exclusive Queue

To allow only one consumer you can enable the Exclusive feature of the queue :

var options = new ConsumerOptions
{
    QueueExclusive  = true, // set exclusive feature on queue (need queue recreation if changed)
};
Limits
var options = new ConsumerOptions
{
    PrefetchCount = 10, // set the prefetch amount of message read by this consumer
    PrefetchGlobal = false // channel global or by consumer limit
};
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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
6.4.4 565 11/25/2023
6.4.2 427 11/25/2023
6.4.1 403 11/24/2023
6.4.0 915 9/11/2022
6.3.1 910 9/11/2022
6.3.0 881 9/11/2022
6.2.2.8 818 1/5/2022
6.2.2.7 815 12/14/2021
6.2.2.6 791 12/10/2021
6.2.2.5 992 12/9/2021
6.2.2.4 809 12/9/2021
6.2.2.2 829 12/9/2021
6.2.2.2-alpha 669 12/5/2021
6.2.2.1-alpha 769 10/30/2021
6.2.2-alpha 717 10/28/2021
0.2.0-beta002 714 10/25/2021
0.2.0-beta001 758 10/25/2021
0.2.0-alpha 712 10/26/2021
0.1.2 1,352 10/4/2021 0.1.2 is deprecated because it is no longer maintained.
0.1.2-beta003 842 10/17/2021
0.1.2-beta002 886 10/17/2021
0.1.2-beta001 925 10/10/2021
0.1.1 1,250 10/2/2021 0.1.1 is deprecated because it is no longer maintained.
0.1.0 1,277 10/2/2021 0.1.0 is deprecated because it is no longer maintained.
0.0.2-beta-3 831 9/26/2021
0.0.2-beta-2 828 9/26/2021
0.0.2-beta 799 9/26/2021
0.0.1 1,193 9/26/2021 0.0.1 is deprecated because it is no longer maintained.