# AspireRabbitMQExtensions Methods

- Package: [Aspire.RabbitMQ.Client](/reference/api/csharp/aspire.rabbitmq.client.md)
- Type: [AspireRabbitMQExtensions](/reference/api/csharp/aspire.rabbitmq.client/aspirerabbitmqextensions.md)
- Kind: `Methods`
- Members: `2`

Extension methods for connecting to a RabbitMQ message broker.

## AddKeyedRabbitMQClient(IHostApplicationBuilder, string, Action<RabbitMQClientSettings>, Action<ConnectionFactory>)

- Name: `AddKeyedRabbitMQClient(IHostApplicationBuilder, string, Action<RabbitMQClientSettings>, Action<ConnectionFactory>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.RabbitMQ.Client/AspireRabbitMQExtensions.cs#L60-L63)

Registers `Client.IConnection` as a keyed singleton for the given `name` in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

```csharp
public static class AspireRabbitMQExtensions
{
    public static void AddKeyedRabbitMQClient(
        this IHostApplicationBuilder builder,
        string name,
        Action<RabbitMQClientSettings>? configureSettings = null,
        Action<ConnectionFactory>? configureConnectionFactory = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `name` (`string`)
  The name of the component, which is used as the `ServiceDescriptor.ServiceKey` of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<RabbitMQClientSettings>`) `optional`
  An optional method that can be used for customizing the [RabbitMQClientSettings](/reference/api/csharp/aspire.rabbitmq.client/rabbitmqclientsettings.md). It's invoked after the settings are read from the configuration.
- `configureConnectionFactory` (`Action<ConnectionFactory>`) `optional`
  An optional method that can be used for customizing the `Client.ConnectionFactory`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:RabbitMQ:Client:{name}" section.

## AddRabbitMQClient(IHostApplicationBuilder, string, Action<RabbitMQClientSettings>, Action<ConnectionFactory>)

- Name: `AddRabbitMQClient(IHostApplicationBuilder, string, Action<RabbitMQClientSettings>, Action<ConnectionFactory>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Components/Aspire.RabbitMQ.Client/AspireRabbitMQExtensions.cs#L43)

Registers `Client.IConnection` as a singleton in the services provided by the `builder`. Enables retries, corresponding health check, logging, and telemetry.

```csharp
public static class AspireRabbitMQExtensions
{
    public static void AddRabbitMQClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<RabbitMQClientSettings>? configureSettings = null,
        Action<ConnectionFactory>? configureConnectionFactory = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<RabbitMQClientSettings>`) `optional`
  An optional method that can be used for customizing the [RabbitMQClientSettings](/reference/api/csharp/aspire.rabbitmq.client/rabbitmqclientsettings.md). It's invoked after the settings are read from the configuration.
- `configureConnectionFactory` (`Action<ConnectionFactory>`) `optional`
  An optional method that can be used for customizing the `Client.ConnectionFactory`. It's invoked after the options are read from the configuration.

## Remarks

Reads the configuration from "Aspire:RabbitMQ:Client" section.
