/// <summary>
        /// Constructs the transport, connecting to the service bus pointed to by the connection string.
        /// </summary>
        public AzureServiceBusTransport(string connectionString, string queueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, INameFormatter nameFormatter, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _nameFormatter = nameFormatter;

            if (queueName != null)
            {
                // this never happens
                if (queueName.StartsWith(MagicSubscriptionPrefix))
                {
                    throw new ArgumentException($"Sorry, but the queue name '{queueName}' cannot be used because it conflicts with Rebus' internally used 'magic subscription prefix': '{MagicSubscriptionPrefix}'. ");
                }

                Address           = _nameFormatter.FormatQueueName(queueName);
                _subscriptionName = _nameFormatter.FormatSubscriptionName(queueName);
            }

            _connectionString  = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
            _asyncTaskFactory  = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory));
            _cancellationToken = cancellationToken;
            _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>();
            _managementClient = new ManagementClient(connectionString);
        }
        /// <summary>
        /// Constructs the transport, connecting to the service bus pointed to by the connection string.
        /// </summary>
        public AzureServiceBusTransport(string connectionString, string queueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, INameFormatter nameFormatter, CancellationToken cancellationToken = default(CancellationToken), ITokenProvider tokenProvider = null)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (asyncTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(asyncTaskFactory));
            }

            _nameFormatter = nameFormatter;

            if (queueName != null)
            {
                // this never happens
                if (queueName.StartsWith(MagicSubscriptionPrefix))
                {
                    throw new ArgumentException($"Sorry, but the queue name '{queueName}' cannot be used because it conflicts with Rebus' internally used 'magic subscription prefix': '{MagicSubscriptionPrefix}'. ");
                }

                Address           = _nameFormatter.FormatQueueName(queueName);
                _subscriptionName = _nameFormatter.FormatSubscriptionName(queueName);
            }

            _connectionString  = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
            _cancellationToken = cancellationToken;
            _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>();

            if (tokenProvider != null)
            {
                var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                _managementClient = new ManagementClient(connectionStringBuilder, tokenProvider);
                _endpoint         = connectionStringBuilder.Endpoint;
                _transportType    = connectionStringBuilder.TransportType;
            }
            else
            {
                _managementClient = new ManagementClient(connectionString);
            }

            _tokenProvider = tokenProvider;

            _messageLockRenewalTask = asyncTaskFactory.Create("Peek Lock Renewal", RenewPeekLocks, prettyInsignificant: true, intervalSeconds: 10);
        }
 /// <summary>
 /// Formats the subscription name into a usable name on ASB, normalizing if needed.
 /// </summary>
 public string FormatSubscriptionName(string subscriptionName)
 {
     return(_innerFormatter.FormatSubscriptionName(subscriptionName));
 }