# RabbitMQBuilderExtensions Methods

- Package: [Aspire.Hosting.RabbitMQ](/reference/api/csharp/aspire.hosting.rabbitmq.md)
- Type: [RabbitMQBuilderExtensions](/reference/api/csharp/aspire.hosting.rabbitmq/rabbitmqbuilderextensions.md)
- Kind: `Methods`
- Members: `5`

Provides extension methods for adding RabbitMQ resources to an `Hosting.IDistributedApplicationBuilder`.

## AddRabbitMQ(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?)

- Name: `AddRabbitMQ(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RabbitMQServerResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs#L37-L87)

Adds a RabbitMQ container to the application model.

```csharp
public static class RabbitMQBuilderExtensions
{
    public static IResourceBuilder<RabbitMQServerResource> AddRabbitMQ(
        this IDistributedApplicationBuilder builder,
        string name,
        IResourceBuilder<ParameterResource>? userName = null,
        IResourceBuilder<ParameterResource>? password = null,
        int? port = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used as the connection string name when referenced in a dependency.
- `userName` (`IResourceBuilder<ParameterResource>`) `optional`
  The parameter used to provide the user name for the RabbitMQ resource. If `null` a default value will be used.
- `password` (`IResourceBuilder<ParameterResource>`) `optional`
  The parameter used to provide the password for the RabbitMQ resource. If `null` a random password will be generated.
- `port` (`int?`) `optional`
  The host port that the underlying container is bound to when running locally.

## Returns

`IResourceBuilder<RabbitMQServerResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This version of the package defaults to the tag of the container image.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithDataBindMount(IResourceBuilder<RabbitMQServerResource>, string, bool)

- Name: `WithDataBindMount(IResourceBuilder<RabbitMQServerResource>, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RabbitMQServerResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs#L118-L122)

Adds a bind mount for the data folder to a RabbitMQ container resource.

```csharp
public static class RabbitMQBuilderExtensions
{
    public static IResourceBuilder<RabbitMQServerResource> WithDataBindMount(
        this IResourceBuilder<RabbitMQServerResource> builder,
        string source,
        bool isReadOnly = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RabbitMQServerResource>`)
  The resource builder.
- `source` (`string`)
  The source directory on the host to mount into the container.
- `isReadOnly` (`bool`) `optional`
  A flag that indicates if this is a read-only mount.

## Returns

`IResourceBuilder<RabbitMQServerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithDataVolume(IResourceBuilder<RabbitMQServerResource>, string?, bool)

- Name: `WithDataVolume(IResourceBuilder<RabbitMQServerResource>, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RabbitMQServerResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs#L101-L104)

Adds a named volume for the data folder to a RabbitMQ container resource.

```csharp
public static class RabbitMQBuilderExtensions
{
    public static IResourceBuilder<RabbitMQServerResource> WithDataVolume(
        this IResourceBuilder<RabbitMQServerResource> builder,
        string? name = null,
        bool isReadOnly = false)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RabbitMQServerResource>`)
  The resource builder.
- `name` (`string?`) `optional`
  The name of the volume. Defaults to an auto-generated name based on the application and resource names.
- `isReadOnly` (`bool`) `optional`
  A flag that indicates if this is a read-only volume.

## Returns

`IResourceBuilder<RabbitMQServerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithManagementPlugin(IResourceBuilder<RabbitMQServerResource>)

- Name: `WithManagementPlugin(IResourceBuilder<RabbitMQServerResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RabbitMQServerResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs#L139-L141)

Configures the RabbitMQ container resource to enable the RabbitMQ management plugin.

```csharp
public static class RabbitMQBuilderExtensions
{
    public static IResourceBuilder<RabbitMQServerResource> WithManagementPlugin(
        this IResourceBuilder<RabbitMQServerResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RabbitMQServerResource>`)
  The resource builder.

## Returns

`IResourceBuilder<RabbitMQServerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Exceptions

- `DistributedApplicationException` -- Thrown when the current container image and tag do not match the defaults for [RabbitMQServerResource](/reference/api/csharp/aspire.hosting.rabbitmq/rabbitmqserverresource.md).

## Remarks

This method only supports custom tags matching the default RabbitMQ ones for the corresponding management tag to be inferred automatically, e.g. `4`, `4.0-alpine`, `4.0.2-management-alpine`, etc. Calling this method on a resource configured with an unrecognized image registry, name, or tag will result in a `Hosting.DistributedApplicationException` being thrown. This version of the package defaults to the tag of the container image.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithManagementPlugin(IResourceBuilder<RabbitMQServerResource>, int?)

- Name: `WithManagementPlugin(IResourceBuilder<RabbitMQServerResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<RabbitMQServerResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.RabbitMQ/RabbitMQBuilderExtensions.cs#L173-L232)

Configures the RabbitMQ container resource to enable the RabbitMQ management plugin.

```csharp
public static class RabbitMQBuilderExtensions
{
    public static IResourceBuilder<RabbitMQServerResource> WithManagementPlugin(
        this IResourceBuilder<RabbitMQServerResource> builder,
        int? port)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<RabbitMQServerResource>`)
  The resource builder.
- `port` (`int?`)
  The host port that can be used to access the management UI page when running locally.

## Returns

`IResourceBuilder<RabbitMQServerResource>` -- The `ApplicationModel.IResourceBuilder`1`.

## Exceptions

- `DistributedApplicationException` -- Thrown when the current container image and tag do not match the defaults for [RabbitMQServerResource](/reference/api/csharp/aspire.hosting.rabbitmq/rabbitmqserverresource.md).

## Remarks

Use [RabbitMQBuilderExtensions.WithManagementPlugin(IResourceBuilder<RabbitMQServerResource>)](/reference/api/csharp/aspire.hosting.rabbitmq/rabbitmqbuilderextensions/methods.md#withmanagementplugin-iresourcebuilder-rabbitmqserverresource) to specify a port to access the RabbitMQ management UI page.

```csharp
var rabbitmq = builder.AddRabbitMQ("rabbitmq")
                      .WithDataVolume()
                      .WithManagementPlugin(port: 15672);
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
