Wire up RawRabbit with Autfac!

autofac, rabbitmq, ioc, rawrabbit, async, dotnetcore, message-bus
Install-Package RawRabbit.DependencyInjection.Autofac -Version 2.0.0-rc5


Looking for documentation of 1.x? Click here


Build Status Documentation Status NuGet GitHub release Slack Status

Quick introduction

RawRabbit is a modern .NET framework for communication over RabbitMQ. The modular design and middleware oriented architecture makes the client highly customizable while providing sensible default for topology, routing and more. Documentation for version 2.x of the is currently found under /docs.

Configure, enrich and extend

RawRabbit is configured with RawRabbitOptions, an options object that makes it possible to register client configuration, plugins as well as override internal services

var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions
  ClientConfiguration = new ConfigurationBuilder()
  Plugins = p => p
    .UsePolly(c => c
        .UsePolicy(queueBindPolicy, PolicyKeys.QueueBind)
        .UsePolicy(queueDeclarePolicy, PolicyKeys.QueueDeclare)
        .UsePolicy(exchangeDeclarePolicy, PolicyKeys.ExchangeDeclare)
  DependencyInjection = ioc => ioc
    .AddSingleton<IChannelFactory, CustomChannelFactory>()


Set up strongly typed publish/subscribe in just a few lines of code.

var client = RawRabbitFactory.CreateSingleton();
await client.SubscribeAsync<BasicMessage>(async msg =>
  Console.WriteLine($"Received: {msg.Prop}.");

await client.PublishAsync(new BasicMessage { Prop = "Hello, world!"});


RawRabbits request/response (RPC) implementation uses the direct reply-to feature for better performance and lower resource allocation.

var client = RawRabbitFactory.CreateSingleton();
client.RespondAsync<BasicRequest, BasicResponse>(async request =>
  return new BasicResponse();

var response = await client.RequestAsync<BasicRequest, BasicResponse>();

Ack, Nack, Reject and Retry

Unlike many other clients, basic.ack, basic.nack and basic.reject are first class citizen in the message handler

var client = RawRabbitFactory.CreateSingleton();
await client.SubscribeAsync<BasicMessage>(async msg =>
    return new Nack(requeue: true);
  return new Ack();

In addition to the basic acknowledgements, RawRabbit also support delayed retries

var client = RawRabbitFactory.CreateSingleton();
await client.SubscribeAsync<BasicMessage>(async msg =>
    return new Ack();
  catch (Exception e)
    return Retry.In(TimeSpan.FromSeconds(30));

Granular control for each call

Add or change properties in the IPipeContext to tailor calls for specific type of messages. This makes it possible to modifly the topology features for calls, publish confirm timeout, consumer concurrency and much more

await subscriber.SubscribeAsync<BasicMessage>(received =>
  return Task.FromResult(true);
}, ctx => ctx
  .UseSubscribeConfiguration(cfg => cfg
    .Consume(c => c
    .FromDeclaredQueue(q => q
      .WithArgument(QueueArgument.DeadLetterExchange, "dlx"))
    .OnDeclaredExchange(e=> e