- 
                Notifications
    
You must be signed in to change notification settings  - Fork 716
 
Ensure RabbitMQ WithDataVolume/WithDataBindMount methods actually enable persistent storage #3152
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
Changes from all commits
1bdda5b
              aa68171
              66a8eea
              316facc
              ff73bc8
              6aed624
              08a0fa8
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -48,7 +48,9 @@ public static IResourceBuilder<RabbitMQServerResource> AddRabbitMQ(this IDistrib | |
| /// <param name="isReadOnly">A flag that indicates if this is a read-only volume.</param> | ||
| /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns> | ||
| public static IResourceBuilder<RabbitMQServerResource> WithDataVolume(this IResourceBuilder<RabbitMQServerResource> builder, string? name = null, bool isReadOnly = false) | ||
| => builder.WithVolume(name ?? VolumeNameGenerator.CreateVolumeName(builder, "data"), "/var/lib/rabbitmq", isReadOnly); | ||
| => builder | ||
| .WithVolume(name ?? VolumeNameGenerator.CreateVolumeName(builder, "data"), "/var/lib/rabbitmq", isReadOnly) | ||
| .RunWithStableNodeName(); | ||
| 
     | 
||
| /// <summary> | ||
| /// Adds a bind mount for the data folder to a RabbitMQ container resource. | ||
| 
        
          
        
         | 
    @@ -58,5 +60,21 @@ public static IResourceBuilder<RabbitMQServerResource> WithDataVolume(this IReso | |
| /// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param> | ||
| /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns> | ||
| public static IResourceBuilder<RabbitMQServerResource> WithDataBindMount(this IResourceBuilder<RabbitMQServerResource> builder, string source, bool isReadOnly = false) | ||
| => builder.WithBindMount(source, "/var/lib/rabbitmq", isReadOnly); | ||
| => builder.WithBindMount(source, "/var/lib/rabbitmq", isReadOnly) | ||
| .RunWithStableNodeName(); | ||
| 
     | 
||
| private static IResourceBuilder<RabbitMQServerResource> RunWithStableNodeName(this IResourceBuilder<RabbitMQServerResource> builder) | ||
| { | ||
| if (builder.ApplicationBuilder.ExecutionContext.IsRunMode) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when you publish? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 
 
 So ultimately, what happens after publish depends on what   | 
||
| { | ||
| builder.WithEnvironment(context => | ||
| { | ||
| // Set a stable node name so queue storage is consistent between sessions | ||
| var nodeName = $"{builder.Resource.Name}@localhost"; | ||
| context.EnvironmentVariables["RABBITMQ_NODENAME"] = nodeName; | ||
| }); | ||
| } | ||
| 
     | 
||
| return builder; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
.PublishAsContainer();necessary?There was a problem hiding this comment.
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.