Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure RabbitMQ WithDataVolume/WithDataBindMount methods actually enable persistent storage #3152

Merged
merged 7 commits into from
Mar 26, 2024

Conversation

DamianEdwards
Copy link
Member

@DamianEdwards DamianEdwards commented Mar 25, 2024

This updates the WithDataVolume and WithDataBindMount methods for RabbitMQ to set the RABBITMQ_NODENAME environment variable to a stable value so that RabbitMQ's internal storage is laid out with a stable storage directory. I also updated TestShop so that it uses persistent storage for its RabbitMQ messaging. I'm able to run TestShop with the orderprocessor resource commented out and make some "orders" by added items to the basket and then clicking the basket summary icon, then stop the session, uncomment orderprocessor, and start a new session, and see that orderprocessor processes the order messages from the previous session.

Fixes #2247

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 25, 2024

private static IResourceBuilder<RabbitMQServerResource> RunWithStableNodeName(this IResourceBuilder<RabbitMQServerResource> builder)
{
if (builder.ApplicationBuilder.ExecutionContext.IsRunMode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when you publish?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption is when you publish the host name of the container is stable, rather than what happens in dev where we randomize the port every time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More details about how RabbitMQ auto-assigns node names in their docs: https://www.rabbitmq.com/docs/clustering#node-names and https://www.rabbitmq.com/docs/configure

From the latter link:

The node name should be unique per Erlang-node-and-machine combination. To run multiple nodes, see the clustering guide.

Default:
Unix: rabbit@$HOSTNAME
Windows: rabbit@%COMPUTERNAME%

So ultimately, what happens after publish depends on what $HOSTNAME results in on the container where RabbitMQ is running.

@eerhardt
Copy link
Member

Is it possible to add some tests?

playground/TestShop/AppHost/Program.cs Outdated Show resolved Hide resolved
var rabbitMqPw = builder.AddParameter("rabbitmqpw", secret: true);
var messaging = builder.AddRabbitMQ("messaging", password: rabbitMqPw)
.WithDataVolume()
.PublishAsContainer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is .PublishAsContainer(); necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add that, it was there already.

DamianEdwards and others added 2 commits March 25, 2024 18:26
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@DamianEdwards
Copy link
Member Author

Is it possible to add some tests?

@eerhardt I logged #3185 to follow up on tests for these methods.

@DamianEdwards DamianEdwards merged commit a24cd1e into main Mar 26, 2024
8 checks passed
@DamianEdwards DamianEdwards deleted the damianedwards/rabbitmq-volume branch March 26, 2024 17:49
DamianEdwards added a commit that referenced this pull request Mar 26, 2024
…ble persistent storage (#3152)

* Use stable node name for RabbitMQ resources

* Update TestShop to use durable messages

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
DamianEdwards added a commit that referenced this pull request Mar 26, 2024
…ble persistent storage (#3152) (#3186)

* Use stable node name for RabbitMQ resources
* Update TestShop to use durable messages

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@danmoseley danmoseley mentioned this pull request Apr 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AddRabbitMQ method with volume mounts does not persist queues across restarts by default
3 participants