FastCSharp.RabbitSubscriber 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FastCSharp.RabbitSubscriber --version 1.0.0
NuGet\Install-Package FastCSharp.RabbitSubscriber -Version 1.0.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="FastCSharp.RabbitSubscriber" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FastCSharp.RabbitSubscriber --version 1.0.0
#r "nuget: FastCSharp.RabbitSubscriber, 1.0.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 FastCSharp.RabbitSubscriber as a Cake Addin
#addin nuget:?package=FastCSharp.RabbitSubscriber&version=1.0.0

// Install FastCSharp.RabbitSubscriber as a Cake Tool
#tool nuget:?package=FastCSharp.RabbitSubscriber&version=1.0.0

FastCSharp's RabbitMQ Subscriber

RabbitSubscriber provides a simple approach for subscribing to a RabbitMQ queue.
It is a wrapper around the RabbitMQ.Client library.

Usage

All you need to do is create a new subscriber to an existing queue and register a callback.

Program.cs

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using FastCSharp.RabbitSubscriber;

IConfiguration configuration = new ConfigurationBuilder()
    .AddJsonFile("rabbitsettings.json", true, true)
    .Build();
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());


var exchange = new RabbitSubscriberFactory(configuration, loggerFactory);
using var subscriber = exchange.NewSubscriber<Message>("TASK_QUEUE");
subscriber.Register(async (message) =>
{
    Console.WriteLine($"Received {message?.Text}");
    return await Task.Run<bool>(()=>true);
});

Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();


public class Message
{
    public Message()
    {
    }

    public string? Text { get; set; }
}

rabbitsettings.json config file sample

{
    "RabbitSubscriberConfig" : 
    {
        "HostName"  : "localhost",
        "Port"      : 5672,
        "VirtualHost": "test-vhost",
        "UserName"  : "guest",
        "Password"  : "guest",
        "HeartbeatTimeout"  : "00:00:20",
        "Queues"    :
        {
            "DIRECT_QUEUE"    : 
            {
                "Name":"test.direct.q",
                "PrefecthCount":1,
                "PrefecthSize":0
            },
            "TOPIC_QUEUE.1"    : 
            {
                "Name":"test.topic.q.1",
                "PrefecthCount":1,
                "PrefecthSize":0
            },
            "TOPIC_QUEUE.2"    : 
            {
                "Name":"test.topic.q.1",
                "PrefecthCount":1,
                "PrefecthSize":0
            },
            "FANOUT_QUEUE.1"    : 
            {
                "Name":"test.fanout.q.1",
                "PrefecthCount":1,
                "PrefecthSize":0
            },
            "FANOUT_QUEUE.2"    : 
            {
                "Name":"test.fanout.q.2",
                "PrefecthCount":1,
                "PrefecthSize":0
            }
        }
    }
}

Adding a Circuit Breaker

The subscriber can be stopped by calling:

subscriber.UnSubscribe();

This is a useful callback when a circuit breaker is triggered and the OnOpen or OnBreak events are fired.

The subscriber can be reset by calling:

subscriber.Reset();

This is a useful callback when a circuit breaker is triggered and the OnReset event is fired.

Check the FastCSharp.CircuitBreaker package for more information on circuit breakers.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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
2.3.0 88 5/7/2024
2.2.0 304 1/5/2024
2.1.0 126 12/19/2023
2.0.0 106 12/17/2023
1.0.0 166 10/20/2023
0.3.0-alpha 94 9/24/2023
0.2.1-alpha 87 9/22/2023
0.2.0-alpha 96 9/22/2023
0.0.1-alpha 91 9/18/2023
0.0.0-alpha 106 4/9/2023