Skip to content

AddRabbitMQ method with volume mounts does not persist queues across restarts by default #2247

@pedershk

Description

@pedershk

RabbitMQ uses its HOSTNAME to set up paths for queues on its internal storage. As the DCP generates a random hostname across restarts, this changes with every invocation of the container. This results in unexpected behavior from the developer's point of view - queues are not persisted across restarts even with persistent storage configured for the container.

This is an example of a statement that will NOT persist queues:

 var rabbitMq = builder
     .AddRabbitMQContainer("rabbitmq-host", 5672, password: rabbitMqPassword)
     .WithVolumeMount("rabbitmq-host-vol", "/var/lib/rabbitmq", VolumeMountType.Named);

If a NODENAME environment variable is set, RabbitMQ uses that to override the HOSTNAME on the container for internal configuration purposes. So directly specifiying the NODENAME variable With i.e. WithEnvironment("NODENAME", "rabbit@localhost") resolves the issue, as in the following statement:

 var rabbitMq = builder
     .AddRabbitMQContainer("rabbitmq-host", 5672, password: rabbitMqPassword)
     .WithEnvironment("NODENAME", "rabbit@localhost")
     .WithVolumeMount("rabbitmq-host-vol", "/var/lib/rabbitmq", VolumeMountType.Named);

Suggestion : set NODENAME by default to a fixed value for RabbitMQ hosts (it's only used internally, so won't affect other RabbitMQ containers running in the same docker engine) - but still allow the user to override by setting it specifically like above. Alternatively, as a minimum, update the RabbitMQ container documentation for Aspire to mention this specifically.

Metadata

Metadata

Assignees

Labels

area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions