public static TopicDescription GetTopicDescription(this Uri address)
        {
            if (string.Compare("sb", address.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new ArgumentException("The invalid scheme was specified: " + address.Scheme);
            }

            var topicPath = address.AbsolutePath.Trim('/');

            var topicDescription = Defaults.CreateTopicDescription(topicPath);

            topicDescription.DefaultMessageTimeToLive = address.GetValueFromQueryString("ttl", topicDescription.DefaultMessageTimeToLive);
            topicDescription.EnableExpress            = address.GetValueFromQueryString("express", topicDescription.EnableExpress);

            return(topicDescription);
        }
Beispiel #2
0
        public static IEnumerable <TopicSubscriptionSettings> GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            if (!IsSubscriptionMessageType(messageType))
            {
                yield break;
            }

            var temporary = IsTemporaryMessageType(messageType);

            var topicDescription = Defaults.CreateTopicDescription(messageNameFormatter.GetMessageName(messageType).ToString());

            topicDescription.EnableExpress = temporary;

            var binding = new TopicSubscription(topicDescription);

            yield return(binding);
        }
Beispiel #3
0
        public static QueueDescription GetQueueDescription(this Uri address)
        {
            if (string.Compare("sb", address.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new ArgumentException("The invalid scheme was specified: " + address.Scheme);
            }

            var queueName = address.AbsolutePath.Trim('/');

            var queueDescription = Defaults.CreateQueueDescription(queueName);

            int autoDeleteOnIdleSeconds = address.GetValueFromQueryString("autodelete", 0);

            if (autoDeleteOnIdleSeconds > 0)
            {
                queueDescription.AutoDeleteOnIdle = TimeSpan.FromSeconds(autoDeleteOnIdleSeconds);
            }

            queueDescription.EnableExpress = address.GetValueFromQueryString("express", queueDescription.EnableExpress);

            return(queueDescription);
        }
Beispiel #4
0
        public static async Task <SubscriptionDescription> CreateTopicSubscriptionSafeAsync(this NamespaceManager namespaceManager, string subscriptionName,
                                                                                            string topicPath, string queuePath, QueueDescription queueDescription)
        {
            var description = Defaults.CreateSubscriptionDescription(topicPath, subscriptionName, queueDescription, queuePath);

            var create = true;
            SubscriptionDescription subscriptionDescription = null;

            try
            {
                subscriptionDescription = await namespaceManager.GetSubscriptionAsync(topicPath, subscriptionName).ConfigureAwait(false);

                if (queuePath.Equals(subscriptionDescription.ForwardTo))
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Updating subscription: {0} ({1} -> {2})", subscriptionDescription.Name, subscriptionDescription.TopicPath,
                                         subscriptionDescription.ForwardTo);
                    }

                    await namespaceManager.UpdateSubscriptionAsync(description).ConfigureAwait(false);

                    create = false;
                }
                else
                {
                    if (_log.IsWarnEnabled)
                    {
                        _log.WarnFormat("Removing invalid subscription: {0} ({1} -> {2})", subscriptionDescription.Name, subscriptionDescription.TopicPath,
                                        subscriptionDescription.ForwardTo);
                    }

                    await namespaceManager.DeleteSubscriptionAsync(topicPath, subscriptionName).ConfigureAwait(false);
                }
            }
            catch (MessagingEntityNotFoundException)
            {
            }

            if (create)
            {
                var created = false;
                try
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Creating subscription {0} -> {1}", topicPath, queuePath);
                    }


                    subscriptionDescription = await namespaceManager.CreateSubscriptionAsync(description).ConfigureAwait(false);

                    created = true;
                }
                catch (MessagingEntityAlreadyExistsException)
                {
                }
                catch (MessagingException mex)
                {
                    if (mex.Message.Contains("(409)"))
                    {
                    }
                    else
                    {
                        throw;
                    }
                }

                if (!created)
                {
                    subscriptionDescription = await namespaceManager.GetSubscriptionAsync(topicPath, subscriptionName).ConfigureAwait(false);
                }
            }

            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscription: {0} ({1} -> {2})", subscriptionDescription.Name, subscriptionDescription.TopicPath,
                                 subscriptionDescription.ForwardTo);
            }

            return(subscriptionDescription);
        }