RabbitMQMiddleware.Implementation 1.0.3

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

// Install RabbitMQMiddleware.Implementation as a Cake Tool
#tool nuget:?package=RabbitMQMiddleware.Implementation&version=1.0.3

RabbitMQMiddleware

RabbitMQ middleware for .net, suitable for clean architecture

Install the package

Find the package through NuGet Package Manager or install it with following command.

Interface

dotnet add package RabbitMQMiddleware.Contract

Implementation

dotnet add package RabbitMQMiddleware.Implementation

note: in clean architecture add "Interface" library to "Application" layer/project and add "Implementation" library to "Infrastructure" layer/project

Register Services

Add the following in Program.cs

builder.Services.AddRabbitMQMiddleware(builder.Configuration);

Add RabbitMq Configuration

Add the following in appsettings.json

  "RabbitMqConfiguration": {
    "HostName": "192.168.1.1",
    "VirtualHost": "/",
    "Port": "5672",
    "Username": "username",
    "Password": "password"
  }

How To Use

For send message inject IProducerService

  private readonly IProducerService<string> _producerService;
  public ClassName(IProducerService<string> producerService)
  {
    _producerService = producerService;
  }
  public void SendMessage(string message)
  {
    _producerService.Send(message: message, exchangeName: "Exchange Name",
    exchangeType: "direct", queueName: "Queue Name", routingKey: "Routing Key");
  }

For receive message inject IConsumerService

  private readonly IConsumerService _consumerService;
  public ClassName(IConsumerService consumerService)
  {
    _consumerService = consumerService;
  }
  public async Task Reciver()
  {
    var model = _consumerService.GetRabbitModel(exchangeName: "Exchange Name",
    exchangeType: "direct", queueName: "Queue Name", routingKey: "Routing Key");
    var consumer = new AsyncEventingBasicConsumer(model);

    consumer.Received += async (ch, ea) =>
    {
      var body = ea.Body.ToArray();
      var item = JsonSerializer.Deserialize<string>(System.Text.Encoding.UTF8.GetString(body));
      //Implement your business

      model.BasicAck(ea.DeliveryTag, false);

      await Task.CompletedTask;
    };
    model.BasicConsume(queue: "Queue Name", false, consumer);
  }
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
1.0.3 167 2/13/2024
1.0.2 64 2/13/2024
1.0.1 107 1/20/2024
1.0.0 166 12/25/2023