/// <summary>
        /// Configures an AzureServiceBus host using a connection string (Endpoint=...., etc).
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="connectionString">The connection string in the proper format</param>
        /// <param name="hostConfigurator">The configuration callback to configure the AzureServiceBus.</param>
        public static void UseAzureServiceBus(this IMassTransitBuilder builder, string connectionName, string connectionString, Action <IServiceBusHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            // in case they pass a URI by mistake (it happens)
            if (Uri.TryCreate(connectionString, UriKind.Absolute, out var hostAddress))
            {
                UseAzureServiceBus(builder, connectionName, hostAddress, hostConfigurator);
                return;
            }

            var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
            var hostBuilder      = new ServiceBusHostBuilder(builder.Services, connectionName, namespaceManager.Address);

            hostBuilder.UseTokenProvider(namespaceManager.Settings.TokenProvider);
            hostBuilder.UseOperationTimeout(namespaceManager.Settings.OperationTimeout);

            hostConfigurator?.Invoke(hostBuilder);
        }
        /// <summary>
        /// Configures an AzureServiceBus host by using the specified application configuration.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="configuration">The <see cref="IConfiguration"/> being bound.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the AzureServiceBus.</param>
        public static void UseAzureServiceBus(this IMassTransitBuilder builder, IConfiguration configuration, Action <IServiceBusHostBuilder> hostConfigurator = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var connectionName = configuration["ConnectionName"];
            var hostBuilder    = new ServiceBusHostBuilder(builder.Services, connectionName, configuration);

            hostConfigurator?.Invoke(hostBuilder);
        }
        /// <summary>
        /// Configures an AzureServiceBus host using a MassTransit host address.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="hostAddress">The address of the service bus namespace and accompanying service scope in MassTransit format (sb://namespace.servicebus.windows.net/scope).</param>
        /// <param name="hostConfigurator">The configuration callback to configure the AzureServiceBus.</param>
        public static void UseAzureServiceBus(this IMassTransitBuilder builder, string connectionName, Uri hostAddress, Action <IServiceBusHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (hostAddress == null)
            {
                throw new ArgumentNullException(nameof(hostAddress));
            }

            var hostBuilder = new ServiceBusHostBuilder(builder.Services, connectionName, hostAddress);

            hostConfigurator?.Invoke(hostBuilder);
        }