diff --git a/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs b/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs index bc8db946f3..979d19e2d8 100644 --- a/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs +++ b/src/ServiceControl.Transports.RabbitMQ/RabbitMQConventionalRoutingTransportCustomization.cs @@ -1,7 +1,9 @@ namespace ServiceControl.Transports.RabbitMQ { using System; + using System.Collections.Generic; using System.Linq; + using System.Text; using BrokerThroughput; using Microsoft.Extensions.DependencyInjection; using NServiceBus; @@ -22,8 +24,17 @@ protected override RabbitMQTransport CreateTransport(TransportSettings transport throw new InvalidOperationException("Connection string not configured"); } + var connectionStringDictionary = ConnectionConfiguration.ParseNServiceBusConnectionString(transportSettings.ConnectionString, new StringBuilder()); + var disableManagementApi = GetValue(connectionStringDictionary, "DisableManagementApi", "false"); + if (!disableManagementApi.Equals("true", StringComparison.OrdinalIgnoreCase) && !disableManagementApi.Equals("false", StringComparison.OrdinalIgnoreCase)) + { + throw new ArgumentException("The value for 'DisableManagementApi' must be either 'true' or 'false'"); + } + var transport = new RabbitMQTransport(RoutingTopology.Conventional(queueType), transportSettings.ConnectionString, enableDelayedDelivery: false); transport.TransportTransactionMode = transport.GetSupportedTransactionModes().Contains(preferredTransactionMode) ? preferredTransactionMode : TransportTransactionMode.ReceiveOnly; + transport.ManagementApiUrl = GetValue(connectionStringDictionary, "ManagementApiUrl", string.Empty); + transport.UseManagementApi = disableManagementApi.Equals("false", StringComparison.OrdinalIgnoreCase); return transport; } @@ -39,5 +50,10 @@ protected sealed override void AddTransportForMonitoringCore(IServiceCollection services.AddSingleton(); services.AddHostedService(provider => provider.GetRequiredService()); } + + static string GetValue(Dictionary dictionary, string key, string defaultValue) + { + return dictionary.TryGetValue(key, out var value) ? value : defaultValue; + } } } \ No newline at end of file