microsoft / microsoft/aspire

RabbitMQ Container Name Override Issue in Azure Container Apps

Open
#13,782 1 comment 0 reactions 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

# RabbitMQ Container Name Override Issue in Azure Container Apps

## Issue
1. When deploying a RabbitMQ container as an Azure Container App, the container name in Azure is automatically suffixed with a random string (e.g., `{name}-xyz123`).
2. So I override the container name to a fixed name (e.g., `rabbitmq-prod`) during deployment using `PublishAsAzureContainerApp(...)` method.
```cs
var rabbitmqAzureResourceName = builder.AddParameter("rabbitmq-name", "rabbitmq-prod");
var rabbitmq = builder
.AddRabbitMQ("rabbitmq", id, password)
.PublishAsAzureContainerApp((infra, app) =>
{
var rabbitmq = app.Template.Containers.Single(x => x.Value?.Name.Value == "rabbitmq").Value!;
app.Name = rabbitmqAzureResourceName.AsProvisioningParameter(infra);
rabbitmq.Name = rabbitmqAzureResourceName.AsProvisioningParameter(infra);
});
```
3. However, the connection string generated for other projects still uses the original container name (e.g., `rabbitmq`) instead of the overridden name (e.g., `rabbitmq-prod`).
- Expected: `amqp://{ID}:{PW}@rabbitmq-prod:5672`
- Actual: `amqp://{ID}:{PW}@rabbitmq:5672`

## Reproduction Steps

### Configure `AppHost.cs`
```cs
var builder = DistributedApplication.CreateBuilder(args);

// 1. Declare ID/PW for RabbitMQ
var id = builder.AddParameter("rabbitmq-id", "Administrator");
var password = builder.AddParameter("rabbitmq-password", "password1!");

// 2. Declare Azure Resource Name for RabbitMQ (expecting `rabbitmq-prod` in Azure Portal)
var rabbitmqAzureResourceName = builder.AddParameter("rabbitmq-name", "rabbitmq-prod");

// 3. Configure RabbitMQ container
var rabbitmq = builder
.AddRabbitMQ("rabbitmq", id, password)
.WithLifetime(ContainerLifetime.Persistent)
.WithManagementPlugin()
.WithOtlpExporter()
.WithExternalHttpEndpoints()
.PublishAsAzureContainerApp((infra, app) =>
{
// 3-1. Set RabbitMQ container name in Azure
// Intercept and override the name of the RabbitMQ container in Azure
// Otherwise, it will be genterated with a random suffix (e.g., `rabbitmq-xyz123`)
var rabbitmq = app.Template.Containers.Single(x => x.Value?.Name.Value == "rabbitmq").Value!;
app.Name = rabbitmqAzureResourceName.AsProvisioningParameter(infra);
rabbitmq.Name = rabbitmqAzureResourceName.AsProvisioningParameter(infra);
});

// 4. Add ConnectionString reference to RabbitMQ for other projects
// This will add environment variable `RABBITMQ__CONNECTIONSTRING`.
// - Expecting value: `amqp://Administrator:password1!@rabbitmq-prod:5672`
// - Actual value: `amqp://Administrator:password1!@rabbitmq:5672`
var api = builder.AddProject("api")
.WithReference(rabbitmq);

var app = builder.Build()
await app.RunAsync(CancellationToken.None);
```

### Reference
- [GitHub - dotnet/aspire - RabbitMQServerResource.cs#L83-L104](https://github.com/dotnet/aspire/blob/c019ae64900546eba6e0cca08f69c57f9ad14020/src/Aspire.Hosting.RabbitMQ/RabbitMQServerResource.cs#L83L104)

### Expected Behavior
- Container app `api` will have environment variable `RABBITMQ__CONNECTIONSTRING` with value:
- AS-IS: `amqp://Administrator:password1!@rabbitmq:5672`
- TO-BE: `amqp://Administrator:password1!@rabbitmq-prod:5672`

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with RabbitMQServerResource.cs#L83-L104 and trace how the RabbitMQ connection string is generated after PublishAsAzureContainerApp overrides the app and container names. Use the AppHost.cs reproduction from the issue to inspect the generated RABBITMQ__CONNECTIONSTRING value. Done means the referenced API receives rabbitmq-prod, while the RabbitMQ resource still deploys with the overridden Azure name.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, rabbitmq
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.