SimpleQueue.NET.RabbitMQ 1.0.0

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

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

SimpleQueue.RabbitMQ

SimpleQueue.RabbitMQ is a RabbitMQ message queue implementation designed for .NET applications. It provides a robust and scalable mechanism for sending, receiving, and processing messages using RabbitMQ as the message broker.

Features

  • RabbitMQ integration: Uses RabbitMQ for reliable message queuing.
  • Asynchronous message handling: Supports asynchronous sending and receiving of messages.
  • Automatic consumer activation: Automatically registers and activates message consumers.
  • Logging: Integrated with Microsoft.Extensions.Logging for easy logging.
  • Message consumers: Handles messages based on their event types (Added, Updated, Deleted).

Usage

Setup

To configure the RabbitMQ message queue, use the ConfigureRabbitMq method in your Startup class or wherever you configure your services.

using Microsoft.Extensions.DependencyInjection;
using SimpleQueue.RabbitMQ;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.ConfigureRabbitMq("amqp://user:password@localhost:5672");
    }
}

Define Messages

Create a message class that inherits from BaseMessage:

using SimpleQueue;

public class MyMessage : BaseMessage
{
    public string Content { get; set; }
}

Implement Message Handlers

Implement the IMessageHandler<T> interface to handle your messages:

using SimpleQueue;
using System.Threading.Tasks;

public class MyMessageHandler : IMessageHandler<MyMessage>
{
    public Task HandleAddedAsync(MyMessage message)
    {
        // Handle added message
        return Task.CompletedTask;
    }

    public Task HandleUpdatedAsync(MyMessage message)
    {
        // Handle updated message
        return Task.CompletedTask;
    }

    public Task HandleDeletedAsync(MyMessage message)
    {
        // Handle deleted message
        return Task.CompletedTask;
    }
}

Send Messages

Inject the IMessageQueue<MyMessage> into your service or controller and use it to send messages:

using SimpleQueue;
using System.Threading.Tasks;

public class MyService
{
    private readonly IMessageQueue<MyMessage> _messageQueue;

    public MyService(IMessageQueue<MyMessage> messageQueue)
    {
        _messageQueue = messageQueue;
    }

    public Task SendMessageAsync()
    {
        var message = new MyMessage { Content = "Hello, World!", EventType = EventTypes.Added };
        return _messageQueue.SendAsync(message, message.EventType);
    }
}

Receive Messages

The message queue will automatically start receiving messages and pass them to the appropriate handlers based on their event types.

Configure Consumers

The ConfigureRabbitMq method automatically registers and activates message consumers. You can customize this behavior using the activateConsumers parameter:

services.ConfigureRabbitMq("amqp://user:password@localhost:5672", activateConsumers: false);

Logging

SimpleQueue.RabbitMQ uses Microsoft.Extensions.Logging for logging. Make sure to configure logging in your application to see the log messages.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

public class Program
{
    public static void Main(string[] args)
    {
        var host = Host.CreateDefaultBuilder(args)
            .ConfigureServices((context, services) =>
            {
                services.ConfigureRabbitMq("amqp://user:password@localhost:5672");
                services.AddLogging(configure => configure.AddConsole());
            })
            .Build();

        host.Run();
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

This project is licensed under the MIT License. See the MIT file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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
1.1.1 89 7/28/2024
1.1.0 106 7/21/2024
1.0.0 105 7/16/2024