RabbitMQ.NET 3.2.0

dotnet add package RabbitMQ.NET --version 3.2.0                
NuGet\Install-Package RabbitMQ.NET -Version 3.2.0                
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="RabbitMQ.NET" Version="3.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RabbitMQ.NET --version 3.2.0                
#r "nuget: RabbitMQ.NET, 3.2.0"                
#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.
// Install RabbitMQ.NET as a Cake Addin
#addin nuget:?package=RabbitMQ.NET&version=3.2.0

// Install RabbitMQ.NET as a Cake Tool
#tool nuget:?package=RabbitMQ.NET&version=3.2.0                

RabbitMQ Client library for .NET Core

Library Version: v3.1.1

Breaking changes in version 3

If you want to use version 2 then Install

Install-Package RabbitMQ.NET -Version 2.1.0

Installation

Install-Package RabbitMQ.NET

Usage

RabbitMQ.NET is a simple library to Publish and Subscribe easily in .NET Core applications.

Setup DI

var serviceProvider = new ServiceCollection()
        .AddLogging(loggingBuilder =>
        {
            loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
        })
        .AddRabbitMQCore(options =>
        {
            options.HostName = "localhost";
        })
        .BuildServiceProvider();

Get QueueService

var rmq = serviceProvider.GetRequiredService<IQueueService>();

Publisher Examples

Publish on Exchange
var pub1 = rmq.CreatePublisher(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Exchange;
    options.ExchangeName = "exchange.1";
    options.ExchangeType = RabbitMqCore.Enums.ExchangeType.direct;
});
var obj = new SimpleObject() { ID = 1, Name = "One" };
var message = new RabbitMessageOutbound()
{
    Message = JsonConvert.SerializeObject(obj)
};
pub1.SendMessage(message);
Publish on Exchange with Routing Key
var pub2 = rmq.CreatePublisher(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Exchange;
    options.ExchangeName = "exchange.1";
    options.ExchangeType = RabbitMqCore.Enums.ExchangeType.direct;
    options.RoutingKeys.Add("routing.key");
});
var obj2 = new SimpleObject() { ID = 2, Name = "Two" };
var message2 = new RabbitMessageOutbound()
{
    Message = JsonConvert.SerializeObject(obj2)
};
pub2.SendMessage(message2);
Publish on Queue
var pub3 = rmq.CreatePublisher(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Queue;
    options.QueueName = "queue.3";
});
pub3.SendMessage(message);

Subscriber Examples

Subscribe with Exchange, Queue and with Routing Key
var sub1 = rmq.CreateSubscriber(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Exchange;
    options.ExchangeName = "exchange.1";
    options.QueueName = "queue.1";
    options.RoutingKeys.Add("routing.key.1");
});
sub1.Subscribe(opt => { Console.WriteLine("sub 1 called: {0}", opt.ToString()); });
Subscribe with Queue
var sub3 = rmq.CreateSubscriber(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Queue;
    options.QueueName = "queue.3";
});
sub3.Subscribe(opt => { Console.WriteLine("sub 3 message:{0}", opt.Message); });
Subscribe with Exchange. Temporary queue will be created automatically
var sub4 = rmq.CreateSubscriber(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Exchange;
    options.ExchangeName = "exchange.1";
});
sub4.Subscribe(opt => { Console.WriteLine("sub 4 called: {0}", opt.ToString()); });
Subscribe to Exchange with Routing key
var sub5 = rmq.CreateSubscriber(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Exchange;
    options.ExchangeName = "exchange.1";
    options.RoutingKeys.Add("routing.key.2");
});
sub5.Subscribe(opt => { Console.WriteLine("sub 5 called: {0}", opt.ToString()); });
Subscribe to Exchange and Queue with TTL
var sub6 = rmq.CreateSubscriber(options =>
{
    options.ExchangeOrQueue = RabbitMqCore.Enums.ExchangeOrQueue.Exchange;
    options.ExchangeName = "exchange.1";
    options.QueueName = "queue.4";
    options.Arguments.Add(ArgumentStrings.XMessageTTL, 5000);
});
sub6.Subscribe(opt => { Console.WriteLine("sub 6 called: {0}", opt.ToString()); });

License

This library licensed under the MIT license.

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. 
.NET Core netcoreapp3.1 is compatible. 
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
3.2.0 5,897 9/21/2022
3.1.1 469 9/15/2022
3.1.0 433 9/15/2022
3.0.1 449 9/14/2022
3.0.0 459 9/14/2022
2.1.0 452 9/8/2022
2.0.0 423 9/7/2022
1.1.0 439 9/7/2022
1.0.5 432 9/4/2022
1.0.4 487 5/11/2022
1.0.3 347 1/2/2022
1.0.2 296 1/2/2022
1.0.1 294 12/30/2021
1.0.0 561 10/25/2021

Multiple host support