public async Task<ISendTransport> GetSendTransport(Uri address)
        {
            IServiceBusHost host;
            if(!TryGetMatchingHost(address, out host))
                throw new EndpointNotFoundException("The endpoint address specified an unknown host: " + address);

            var queueDescription = address.GetQueueDescription();

            var namespaceManager = await host.NamespaceManager.ConfigureAwait(false);

            string queuePath;
            var namespacePath = namespaceManager.Address.AbsolutePath.Trim('/');
            if (IsInNamespace(queueDescription, namespacePath))
            {
                queueDescription.Path = queueDescription.Path.Replace(namespacePath, "").Trim('/');
                queueDescription = await namespaceManager.CreateQueueSafeAsync(queueDescription).ConfigureAwait(false);

                queuePath = host.GetQueuePath(queueDescription);
            }
            else
            {
                namespaceManager = await host.RootNamespaceManager.ConfigureAwait(false);

                queueDescription = await namespaceManager.CreateQueueSafeAsync(queueDescription).ConfigureAwait(false);

                queuePath = queueDescription.Path;
            }

            MessagingFactory messagingFactory = await host.MessagingFactory.ConfigureAwait(false);

            MessageSender messageSender = await messagingFactory.CreateMessageSenderAsync(queuePath).ConfigureAwait(false);

            return new ServiceBusSendTransport(messageSender);
        }
        public async Task<ISendTransport> GetSendTransport(Uri address)
        {
            IServiceBusHost host = _hosts.FirstOrDefault(
                x => address.ToString().StartsWith(x.Settings.ServiceUri.ToString(), StringComparison.OrdinalIgnoreCase));
            if (host == null)
                throw new EndpointNotFoundException("The endpoint address specified an unknown host: " + address);

            var queueDescription = address.GetQueueDescription();

            var namespaceManager = await host.NamespaceManager;

            var namespacePath = namespaceManager.Address.AbsolutePath.Trim('/');
            if (IsInNamespace(queueDescription, namespacePath))
            {
                queueDescription.Path = queueDescription.Path.Replace(namespacePath, "").Trim('/');
                queueDescription = await namespaceManager.CreateQueueSafeAsync(queueDescription);
            }
            else
            {
                namespaceManager = await host.RootNamespaceManager;

                queueDescription = await namespaceManager.CreateQueueSafeAsync(queueDescription);
            }

            MessagingFactory messagingFactory = await host.MessagingFactory;

            string queuePath = host.GetQueuePath(queueDescription);

            MessageSender messageSender = await messagingFactory.CreateMessageSenderAsync(queuePath);

            var sendTransport = new ServiceBusSendTransport(messageSender);
            return sendTransport;
        }
        public Task<ISendTransport> GetSendTransport(Uri address)
        {
            IServiceBusHost host;
            if (!TryGetMatchingHost(address, out host))
                throw new EndpointNotFoundException("The endpoint address specified an unknown host: " + address);

            return host.RetryPolicy.Retry<ISendTransport>(async () =>
            {
                QueueDescription queueDescription = address.GetQueueDescription();

                string queuePath;
                string namespacePath = host.NamespaceManager.Address.AbsolutePath.Trim('/');

                if (string.IsNullOrEmpty(namespacePath))
                {
                    queueDescription = await host.CreateQueue(queueDescription).ConfigureAwait(false);

                    queuePath = host.GetQueuePath(queueDescription);
                }
                else if (IsInNamespace(queueDescription, namespacePath))
                {
                    queueDescription.Path = queueDescription.Path.Replace(namespacePath, "").Trim('/');
                    queueDescription = await host.CreateQueue(queueDescription).ConfigureAwait(false);

                    queuePath = host.GetQueuePath(queueDescription);
                }
                else
                {
//                    queueDescription = await host.CreateQueue(queueDescription).ConfigureAwait(false);
                    queueDescription = await host.RootNamespaceManager.CreateQueueSafeAsync(queueDescription).ConfigureAwait(false);

                    queuePath = queueDescription.Path;
                }

                MessagingFactory messagingFactory = await host.MessagingFactory.ConfigureAwait(false);

                QueueClient queueClient = messagingFactory.CreateQueueClient(queuePath);

                var client = new QueueSendClient(queueClient);

                return new ServiceBusSendTransport(client, host.Supervisor);
            });
        }
Пример #4
0
        TimeSpan QueueCacheDurationProvider(Uri address)
        {
            var timeSpan = address.GetQueueDescription().AutoDeleteOnIdle;

            return timeSpan > TimeSpan.FromDays(1) ? TimeSpan.FromDays(1) : timeSpan;
        }