@@ -25,20 +25,42 @@ protected override RabbitMQTransport CreateTransport(TransportSettings transport
2525 throw new InvalidOperationException ( "Connection string not configured" ) ;
2626 }
2727
28+ var connectionConfiguration = ConnectionConfiguration . Create ( transportSettings . ConnectionString , string . Empty ) ;
2829 var connectionStringDictionary = ConnectionConfiguration . ParseNServiceBusConnectionString ( transportSettings . ConnectionString , new StringBuilder ( ) ) ;
29- var disableManagementApi = GetValue ( connectionStringDictionary , "DisableManagementApi" , "false" ) ;
30- if ( ! disableManagementApi . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) && ! disableManagementApi . Equals ( "false" , StringComparison . OrdinalIgnoreCase ) )
30+
31+ var disableManagementApiString = GetValue ( connectionStringDictionary , "DisableManagementApi" , "false" ) ;
32+ if ( ! bool . TryParse ( disableManagementApiString , out var disableManagementApi ) )
3133 {
3234 throw new ArgumentException ( "The value for 'DisableManagementApi' must be either 'true' or 'false'" ) ;
3335 }
3436
3537 var transport = new RabbitMQTransport ( RoutingTopology . Direct ( queueType , routingKeyConvention : type => type . FullName . Replace ( "." , "-" ) ) , transportSettings . ConnectionString , enableDelayedDelivery : false ) ;
3638 transport . TransportTransactionMode = transport . GetSupportedTransactionModes ( ) . Contains ( preferredTransactionMode ) ? preferredTransactionMode : TransportTransactionMode . ReceiveOnly ;
37- transport . ManagementApiUrl = GetValue ( connectionStringDictionary , "ManagementApiUrl" , string . Empty ) ;
38- transport . UseManagementApi = disableManagementApi . Equals ( "false" , StringComparison . OrdinalIgnoreCase ) ;
39+ transport . UseManagementApi = ! disableManagementApi ;
3940
40- rabbitMQTransport = transport ;
41+ if ( ! transport . UseManagementApi )
42+ {
43+ rabbitMQTransport = transport ;
44+ return transport ;
45+ }
46+
47+ var url = GetValue ( connectionStringDictionary , "ManagementApiUrl" , string . Empty ) ;
48+ var username = GetValue ( connectionStringDictionary , "ManagementApiUserName" , connectionConfiguration . UserName ) ;
49+ var password = GetValue ( connectionStringDictionary , "ManagementApiPassword" , connectionConfiguration . Password ) ;
4150
51+ if ( ! string . IsNullOrEmpty ( url ) )
52+ {
53+ if ( ! string . IsNullOrEmpty ( username ) && ! string . IsNullOrEmpty ( password ) )
54+ {
55+ transport . ManagementApiConfiguration = new ManagementApiConfiguration ( url , username , password ) ;
56+ }
57+ else
58+ {
59+ transport . ManagementApiConfiguration = new ManagementApiConfiguration ( url ) ;
60+ }
61+ }
62+
63+ rabbitMQTransport = transport ;
4264 return transport ;
4365 }
4466
0 commit comments