Skip to content

Latest commit

 

History

History
84 lines (61 loc) · 2.56 KB

README.md

File metadata and controls

84 lines (61 loc) · 2.56 KB

RabbitMQ adapter library

Version Downloads

The goal of this library is to ease the use of RabbitMQ in a .NET program and gather best practices.

References

How to use

  • Have the NuGet package in your csproj file (can be done manually, with Visual Studio or through nuget command)
<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <PackageReference Include="Withywoods.RabbitMq" Version="X.Y.Z" />
  </ItemGroup>
</Project>
  • Make the code changes to be able to use the library (config & service provider)
// implement the configuration interface (for instance in a configuration class in your app project), or use DefaultRabbitMqConfiguration
using Withywoods.RabbitMq;

public class AppConfiguration : IRabbitMqConfiguration
{
    // explicitely choose where to take the configuration (this is the responibility of the app, not the library)
}

// configure your service provider (for instance in your app Startup class)
using Withywoods.RabbitMq.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection()
    .AddLogging()
    .AddRabbitMqFactory(Configuration);
  • Use the channel factory
using Withywoods.RabbitMq;

private readonly IChannelFactory _channelFactory;

public MyService(IChannelFactory channelFactory)
{
    _channelFactory = channelFactory;
}

public async Task DoStuff()
{
    using var channel = channelFactory.Create();
}

How to debug

  • Have an instance of RabbitMQ
docker run -d --rm -p 5672:5672 --hostname rabbit.local --name rabbitmq382 rabbitmq:3.8.2

How to run the samples

# from command window #1
dotnet run --project samples\RabbitMqConsumerSample host.docker.internal 5672

# from command window #2
dotnet run --project samples\RabbitMqPublisherSample host.docker.internal 5672