11namespace NServiceBus . Transport . RabbitMQ
22{
33 using System . Threading . Tasks ;
4+ using global ::RabbitMQ . Client ;
45
56 class QueueCreator : ICreateQueues
67 {
@@ -17,28 +18,28 @@ public QueueCreator(ConnectionFactory connectionFactory, IRoutingTopology routin
1718
1819 public Task CreateQueueIfNecessary ( QueueBindings queueBindings , string identity )
1920 {
20- foreach ( var receivingAddress in queueBindings . ReceivingAddresses )
21+ using ( var connection = connectionFactory . CreateAdministrationConnection ( ) )
22+ using ( var channel = connection . CreateModel ( ) )
2123 {
22- CreateQueueIfNecessary ( receivingAddress ) ;
23- }
24+ foreach ( var receivingAddress in queueBindings . ReceivingAddresses )
25+ {
26+ CreateQueueIfNecessary ( channel , receivingAddress ) ;
27+ }
2428
25- foreach ( var sendingAddress in queueBindings . SendingAddresses )
26- {
27- CreateQueueIfNecessary ( sendingAddress ) ;
29+ foreach ( var sendingAddress in queueBindings . SendingAddresses )
30+ {
31+ CreateQueueIfNecessary ( channel , sendingAddress ) ;
32+ }
2833 }
2934
3035 return TaskEx . CompletedTask ;
3136 }
3237
33- void CreateQueueIfNecessary ( string receivingAddress )
38+ void CreateQueueIfNecessary ( IModel channel , string receivingAddress )
3439 {
35- using ( var connection = connectionFactory . CreateAdministrationConnection ( ) )
36- using ( var channel = connection . CreateModel ( ) )
37- {
38- channel . QueueDeclare ( receivingAddress , durableMessagesEnabled , false , false , null ) ;
40+ channel . QueueDeclare ( receivingAddress , durableMessagesEnabled , false , false , null ) ;
3941
40- routingTopology . Initialize ( channel , receivingAddress ) ;
41- }
42+ routingTopology . Initialize ( channel , receivingAddress ) ;
4243 }
4344 }
4445}
0 commit comments