@@ -48,7 +48,9 @@ public static IResourceBuilder<RabbitMQServerResource> AddRabbitMQ(this IDistrib
4848 /// <param name="isReadOnly">A flag that indicates if this is a read-only volume.</param>
4949 /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
5050 public static IResourceBuilder < RabbitMQServerResource > WithDataVolume ( this IResourceBuilder < RabbitMQServerResource > builder , string ? name = null , bool isReadOnly = false )
51- => builder . WithVolume ( name ?? VolumeNameGenerator . CreateVolumeName ( builder , "data" ) , "/var/lib/rabbitmq" , isReadOnly ) ;
51+ => builder
52+ . WithVolume ( name ?? VolumeNameGenerator . CreateVolumeName ( builder , "data" ) , "/var/lib/rabbitmq" , isReadOnly )
53+ . RunWithStableNodeName ( ) ;
5254
5355 /// <summary>
5456 /// Adds a bind mount for the data folder to a RabbitMQ container resource.
@@ -58,5 +60,21 @@ public static IResourceBuilder<RabbitMQServerResource> WithDataVolume(this IReso
5860 /// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
5961 /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
6062 public static IResourceBuilder < RabbitMQServerResource > WithDataBindMount ( this IResourceBuilder < RabbitMQServerResource > builder , string source , bool isReadOnly = false )
61- => builder . WithBindMount ( source , "/var/lib/rabbitmq" , isReadOnly ) ;
63+ => builder . WithBindMount ( source , "/var/lib/rabbitmq" , isReadOnly )
64+ . RunWithStableNodeName ( ) ;
65+
66+ private static IResourceBuilder < RabbitMQServerResource > RunWithStableNodeName ( this IResourceBuilder < RabbitMQServerResource > builder )
67+ {
68+ if ( builder . ApplicationBuilder . ExecutionContext . IsRunMode )
69+ {
70+ builder . WithEnvironment ( context =>
71+ {
72+ // Set a stable node name so queue storage is consistent between sessions
73+ var nodeName = $ "{ builder . Resource . Name } @localhost";
74+ context . EnvironmentVariables [ "RABBITMQ_NODENAME" ] = nodeName ;
75+ } ) ;
76+ }
77+
78+ return builder ;
79+ }
6280}
0 commit comments