Table of Contents

Class RabbitMQTransportServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Excalibur.Dispatch.Transport.RabbitMQ.dll

Extension methods for registering RabbitMQ transport with the service collection.

public static class RabbitMQTransportServiceCollectionExtensions
Inheritance
RabbitMQTransportServiceCollectionExtensions
Inherited Members

Examples

services.AddRabbitMQTransport("events", rmq =>
{
    rmq.HostName("localhost")
       .Port(5672)
       .VirtualHost("/")
       .Credentials("guest", "guest")
       .ConfigureExchange(exchange =>
       {
           exchange.Name("events")
                   .Type(RabbitMQExchangeType.Topic)
                   .Durable(true);
       })
       .ConfigureQueue(queue =>
       {
           queue.Name("order-handlers")
                .Durable(true)
                .PrefetchCount(10);
       })
       .ConfigureBinding(binding =>
       {
           binding.Exchange("events")
                  .Queue("order-handlers")
                  .RoutingKey("orders.*");
       })
       .MapExchange<OrderCreated>("events");
});

Remarks

This class provides the single entry point for RabbitMQ transport configuration.

Use AddRabbitMQTransport(IServiceCollection, string, Action<IRabbitMQTransportBuilder>) to register a named RabbitMQ transport with full fluent configuration support.

Fields

DefaultTransportName

The default transport name when none is specified.

public const string DefaultTransportName = "rabbitmq"

Field Value

string

Methods

AddRabbitMQTransport(IServiceCollection, Action<IRabbitMQTransportBuilder>)

Adds a RabbitMQ transport with the default name and configuration.

public static IServiceCollection AddRabbitMQTransport(this IServiceCollection services, Action<IRabbitMQTransportBuilder> configure)

Parameters

services IServiceCollection

The service collection.

configure Action<IRabbitMQTransportBuilder>

The transport configuration action.

Returns

IServiceCollection

The service collection for chaining.

Examples

// Single transport scenario with default name
services.AddRabbitMQTransport(rmq =>
{
    rmq.HostName("localhost")
       .Credentials("guest", "guest")
       .ConfigureExchange(e => e.Name("events").Type(RabbitMQExchangeType.Topic));
});

Remarks

This overload uses the default transport name "rabbitmq". Use the named overload for multi-transport scenarios.

Exceptions

ArgumentNullException

Thrown when services or configure is null.

AddRabbitMQTransport(IServiceCollection, string)

Adds a RabbitMQ transport with just a connection string and sensible defaults.

public static IServiceCollection AddRabbitMQTransport(this IServiceCollection services, string connectionString)

Parameters

services IServiceCollection

The service collection.

connectionString string

The AMQP connection string (e.g., "amqp://guest:guest@localhost:5672").

Returns

IServiceCollection

The service collection for chaining.

Examples

services.AddRabbitMQTransport("amqp://guest:guest@localhost:5672");

Remarks

This is the simplest way to register RabbitMQ transport. For advanced configuration (exchanges, queues, bindings), use the builder overload.

AddRabbitMQTransport(IServiceCollection, string, Action<IRabbitMQTransportBuilder>)

Adds a RabbitMQ transport with the specified name and configuration.

public static IServiceCollection AddRabbitMQTransport(this IServiceCollection services, string name, Action<IRabbitMQTransportBuilder> configure)

Parameters

services IServiceCollection

The service collection.

name string

The transport name for multi-transport routing.

configure Action<IRabbitMQTransportBuilder>

The transport configuration action.

Returns

IServiceCollection

The service collection for chaining.

Examples

// Named transport for multi-transport scenarios
services.AddRabbitMQTransport("orders", rmq =>
{
    rmq.HostName("orders.rabbitmq.local")
       .ConfigureExchange(e => e.Name("orders").Type(RabbitMQExchangeType.Topic))
       .MapExchange<OrderCreated>("orders");
});

services.AddRabbitMQTransport("payments", rmq =>
{
    rmq.HostName("payments.rabbitmq.local")
       .ConfigureQueue(q => q.Name("payments"))
       .MapQueue<PaymentReceived>("payments");
});

Remarks

This is the primary entry point for RabbitMQ transport configuration. It provides access to all fluent builder APIs for exchange, queue, binding, and dead letter configuration.

Named transports support multi-transport routing scenarios where different message types are routed to different RabbitMQ transports.

Exceptions

ArgumentNullException

Thrown when services or configure is null.

ArgumentException

Thrown when name is null, empty, or whitespace.