async Task <bool> SubscriptionIsReusedAcrossDifferentNamespaces(SubscriptionDescription subscriptionDescription, string sqlFilter, INamespaceManager namespaceManager) { var rules = await namespaceManager.GetRules(subscriptionDescription).ConfigureAwait(false); var filter = rules.First().Filter as SqlFilter; if (filter != null && filter.SqlExpression != sqlFilter) { logger.Debug("Looks like this subscription name is already taken as the sql filter does not match the subscribed event name."); return(true); } return(false); }
public async Task DeleteSubscription(string topicPath, string subscriptionName, SubscriptionMetadata metadata, string sqlFilter, INamespaceManager namespaceManager, string forwardTo) { var meta = metadata as ForwardingTopologySubscriptionMetadata; var subscriptionDescription = subscriptionDescriptionFactory(topicPath, subscriptionName, settings); try { if (await ExistsAsync(topicPath, subscriptionName, metadata.Description, namespaceManager, removeCacheEntry: true).ConfigureAwait(false)) { var ruleDescription = new RuleDescription { Filter = new SqlFilter(sqlFilter), Name = metadata.SubscriptionNameBasedOnEventWithNamespace }; logger.Info($"Removing subscription rule '{ruleDescription.Name}' for event '{meta.SubscribedEventFullName}'."); var subscriptionClient = SubscriptionClient.CreateFromConnectionString(meta.NamespaceInfo.ConnectionString, topicPath, subscriptionName); await subscriptionClient.RemoveRuleAsync(ruleDescription.Name).ConfigureAwait(false); var remainingRules = await namespaceManager.GetRules(subscriptionDescription).ConfigureAwait(false); var namespaceManagerThatCanDelete = namespaceManager as INamespaceManagerAbleToDeleteSubscriptions; if (!remainingRules.Any() && namespaceManagerThatCanDelete != null) { await namespaceManagerThatCanDelete.DeleteSubscription(subscriptionDescription).ConfigureAwait(false); logger.Debug($"Subscription '{subscriptionDescription.UserMetadata}' created as '{subscriptionDescription.Name}' was removed as part of unsubscribe since events are subscribed to."); } } } catch (MessagingException ex) { var loggedMessage = $"{(ex.IsTransient ? "Transient" : "Non transient")} {ex.GetType().Name} occurred on subscription '{subscriptionDescription.Name}' deletion for topic '{subscriptionDescription.TopicPath}' in namespace '{namespaceManager.Address.Host}'."; if (!ex.IsTransient) { logger.Fatal(loggedMessage, ex); throw; } logger.Info(loggedMessage, ex); } }