11namespace ServiceControl . Transports . RabbitMQ
22{
33 using System ;
4+ using System . Collections . Generic ;
45 using System . Linq ;
6+ using System . Text ;
57 using BrokerThroughput ;
68 using Microsoft . Extensions . DependencyInjection ;
79 using NServiceBus ;
@@ -22,8 +24,17 @@ protected override RabbitMQTransport CreateTransport(TransportSettings transport
2224 throw new InvalidOperationException ( "Connection string not configured" ) ;
2325 }
2426
27+ var connectionStringDictionary = ConnectionConfiguration . ParseNServiceBusConnectionString ( transportSettings . ConnectionString , new StringBuilder ( ) ) ;
28+ var disableManagementApi = GetValue ( connectionStringDictionary , "DisableManagementApi" , "false" ) ;
29+ if ( ! disableManagementApi . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) && ! disableManagementApi . Equals ( "false" , StringComparison . OrdinalIgnoreCase ) )
30+ {
31+ throw new ArgumentException ( "The value for 'DisableManagementApi' must be either 'true' or 'false'" ) ;
32+ }
33+
2534 var transport = new RabbitMQTransport ( RoutingTopology . Conventional ( queueType ) , transportSettings . ConnectionString , enableDelayedDelivery : false ) ;
2635 transport . TransportTransactionMode = transport . GetSupportedTransactionModes ( ) . Contains ( preferredTransactionMode ) ? preferredTransactionMode : TransportTransactionMode . ReceiveOnly ;
36+ transport . ManagementApiUrl = GetValue ( connectionStringDictionary , "ManagementApiUrl" , string . Empty ) ;
37+ transport . UseManagementApi = disableManagementApi . Equals ( "false" , StringComparison . OrdinalIgnoreCase ) ;
2738
2839 return transport ;
2940 }
@@ -39,5 +50,10 @@ protected sealed override void AddTransportForMonitoringCore(IServiceCollection
3950 services . AddSingleton < IProvideQueueLength , QueueLengthProvider > ( ) ;
4051 services . AddHostedService ( provider => provider . GetRequiredService < IProvideQueueLength > ( ) ) ;
4152 }
53+
54+ static string GetValue ( Dictionary < string , string > dictionary , string key , string defaultValue )
55+ {
56+ return dictionary . TryGetValue ( key , out var value ) ? value : defaultValue ;
57+ }
4258 }
4359}
0 commit comments