Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="original"></param>
        public void Unsubscribe(Type eventType, Address original)
        {
            var publisherAddress = Address.Parse(AzureServiceBusPublisherAddressConvention.Create(original));
            var subscriptionname = AzureServiceBusSubscriptionNameConvention.Create(eventType);

            if (NamespaceClient.SubscriptionExists(publisherAddress.Queue, subscriptionname))
            {
                NamespaceClient.DeleteSubscription(publisherAddress.Queue, subscriptionname);
            }

            // unhook the listener
        }
        public SubscriptionClient Create(Type eventType, string topicPath, string subscriptionname)
        {
            if (NamespaceClient.TopicExists(topicPath))
            {
                try
                {
                    if (!NamespaceClient.SubscriptionExists(topicPath, subscriptionname))
                    {
                        var description = new SubscriptionDescription(topicPath, subscriptionname)
                        {
                            LockDuration             = LockDuration,
                            RequiresSession          = RequiresSession,
                            DefaultMessageTimeToLive = DefaultMessageTimeToLive,
                            EnableDeadLetteringOnMessageExpiration = EnableDeadLetteringOnMessageExpiration,
                            MaxDeliveryCount        = MaxDeliveryCount,
                            EnableBatchedOperations = EnableBatchedOperations,
                            EnableDeadLetteringOnFilterEvaluationExceptions =
                                EnableDeadLetteringOnFilterEvaluationExceptions
                        };

                        if (eventType != null)
                        {
                            var filter =
                                string.Format(
                                    "[{0}] LIKE '{1}%' OR [{0}] LIKE '%{1}%' OR [{0}] LIKE '%{1}' OR [{0}] = '{1}'",
                                    Headers.EnclosedMessageTypes, eventType.AssemblyQualifiedName);
                            var typefilter = new SqlFilter(filter);

                            NamespaceClient.CreateSubscription(description, typefilter);
                        }
                        else
                        {
                            NamespaceClient.CreateSubscription(description);
                        }
                    }
                }
                catch (MessagingEntityAlreadyExistsException)
                {
                    // the queue already exists or another node beat us to it, which is ok
                }

                return(Factory.CreateSubscriptionClient(topicPath, subscriptionname, ReceiveMode.PeekLock));
            }
            return(null);
        }