Dkeshri.MessageQueue 2.0.7

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

// Install Dkeshri.MessageQueue as a Cake Tool
#tool nuget:?package=Dkeshri.MessageQueue&version=2.0.7                

About

This is an MessageBroker interface that allow to implement various MessageBroker service like RabbitMq, AzureSericeBus etc.

Interfaces

IMessageSender, IMessageReceiver, IStartup, MessageBrokerFactory

How it work

AddMessageBroker serves as the starting point. Clients use this method with IServiceCollection and provide the MessageBroker configuration.

It then utilizes the MessageBrokerFactory to create the sender (IMessageSender) and receiver (IMessageReceiver) objects. These objects are registered in the IServiceCollection dependency injection (DI) container, allowing clients to use these interfaces to send and receive messages.

How to Use

The extension method AddMessageBroker for IServiceCollection helps register services in the IServiceCollection dependency injection (DI) container.

MessageBrokerFactory

Is an abstract class contains CreateSender and CreateReceiver, Implemented library need to provide The CreaterFactory and Provide that Factory in IServiceCollection

public abstract class MessageBrokerFactory
    {
        public abstract IMessageSender CreateSender();
        public abstract IMessageReceiver CreateReceiver();
        public abstract IStartup CreateInitializer();
    }

In your library

Create a ExtentionMethod to MessageBroker, this will give is some basic messageBroker configuration and IServiceCollection Property help you to register your services.

public static class ServiceCollectionExtensions
{      
    public static void AddRabbitMqServices(this MessageBroker messageBroker, YourConfigClass config)
    {
        messageBroker.Services.AddSingleton<MessageBrokerFactory, RabbitMqMessageBroker>();

        // add rest of your services in IServiceCollection


    }

}

Provide Concreate Implementation of MessageBrokerFactory

Example :

internal class RabbitMqMessageBroker : MessageBrokerFactory
{
    private readonly IRabbitMqConnection _connection;
    private IMessageHandler? _messageHandler;
    public RabbitMqMessageBroker(IRabbitMqConnection rabbitMqConnection,IMessageHandler? messageHandler = null)
    {
        _connection = rabbitMqConnection;
        _messageHandler = messageHandler;
    }

    public override IStartup CreateInitializer()
    {
        return new MessageBrokerInitializer(_connection);
    }

    public override IMessageReceiver CreateReceiver()
    {
        return _messageHandler as IMessageReceiver
           ?? throw new InvalidCastException("The injected IMessageHandler does not implement IMessageReceiver.");
    }

    public override IMessageSender CreateSender()
    {
        return new MessageSender(_connection);
    }
}
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.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Dkeshri.MessageQueue:

Package Downloads
Dkeshri.DataSync.DBChangeEmitter

Tracks changes in an MSSQL database and sends updates to Message Brocker Like RabbitMq.

Dkeshri.DataSync.DbChangeReceiver

Subscribe Event of Message Broker like RabbitMq and Apply change to database.

Dkeshri.MessageQueue.RabbitMq

This will help the user manage the connection and allow them to send messages to the RabbitMQ queue. Additionally, there is a RabbitMQ queue receiver that retrieves the messages.

GitHub repositories

This package is not used by any popular GitHub repositories.