private static async Task <ServiceBusAdministrationClient> Cleanup(string connectionString, string inputQueue, string topicName, string rushSubscription, string currencySubscription) { var client = new ServiceBusAdministrationClient(connectionString); if (await client.SubscriptionExistsAsync(topicName, rushSubscription)) { await client.DeleteSubscriptionAsync(topicName, rushSubscription); } if (await client.SubscriptionExistsAsync(topicName, currencySubscription)) { await client.DeleteSubscriptionAsync(topicName, currencySubscription); } if (await client.TopicExistsAsync(topicName)) { await client.DeleteTopicAsync(topicName); } var topicDescription = new CreateTopicOptions(topicName); await client.CreateTopicAsync(topicDescription); if (await client.QueueExistsAsync(inputQueue)) { await client.DeleteQueueAsync(inputQueue); } var queueDescription = new CreateQueueOptions(inputQueue); await client.CreateQueueAsync(queueDescription); return(client); }
protected async Task CreateSubscriptionAsync(string subscription) { try { await _serviceBusAdminClient.DeleteSubscriptionAsync(_topic, subscription); } catch { } await _serviceBusAdminClient.CreateSubscriptionAsync(_topic, subscription); }
async Task DeleteSubscriptionAsync() { if (await _sbAdminClient.SubscriptionExistsAsync(_topicName, _subscriptionName)) { await _sbAdminClient.DeleteSubscriptionAsync(_topicName, _subscriptionName); } }
private async Task DeleteTopicSubscriptionAsync(CancellationToken cancellationToken) { ServiceBusAdministrationClient serviceBusClient = await Settings.GetServiceBusAdminClientAsync(); string entityPath = await Settings.GetEntityPathAsync(); try { bool subscriptionExists = await serviceBusClient.SubscriptionExistsAsync(entityPath, SubscriptionName, cancellationToken); if (subscriptionExists) { Logger.LogTrace("Deleting subscription '{SubscriptionName}' on topic '{Path}'...", SubscriptionName, entityPath); await serviceBusClient.DeleteSubscriptionAsync(entityPath, SubscriptionName, cancellationToken); Logger.LogTrace("Subscription '{SubscriptionName}' deleted on topic '{Path}'", SubscriptionName, entityPath); } else { Logger.LogTrace("Cannot delete topic subscription with name '{SubscriptionName}' because no subscription exists on Service Bus resource", SubscriptionName); } } catch (Exception exception) { Logger.LogWarning(exception, "Failed to delete topic subscription with name '{SubscriptionName}' on Service Bus resource", SubscriptionName); } }
public async Task DisposeAsync() { var adminClient = new ServiceBusAdministrationClient(_fixture.Configuration.ConnectionString); await adminClient.DeleteSubscriptionAsync(_topicName, _subscriptionName); await adminClient.DeleteTopicAsync(_topicName); }
public async Task DisposeAsync() { var adminClient = new ServiceBusAdministrationClient(_sbFixture.Configuration.ConnectionString); await foreach (var subscription in adminClient.GetSubscriptionsAsync(_topicName)) { await adminClient.DeleteSubscriptionAsync(_topicName, subscription.SubscriptionName); } await adminClient.DeleteTopicAsync(_topicName); }
public async Task GetUpdateDeleteTopicAndSubscription() { string topicName = Guid.NewGuid().ToString("D").Substring(0, 8); string subscriptionName = Guid.NewGuid().ToString("D").Substring(0, 8); string connectionString = TestEnvironment.ServiceBusConnectionString; var client = new ServiceBusAdministrationClient(connectionString); var topicOptions = new CreateTopicOptions(topicName); var subscriptionOptions = new CreateSubscriptionOptions(topicName, subscriptionName); await client.CreateTopicAsync(topicOptions); await client.CreateSubscriptionAsync(subscriptionOptions); #region Snippet:GetTopic TopicProperties topic = await client.GetTopicAsync(topicName); #endregion #region Snippet:GetSubscription SubscriptionProperties subscription = await client.GetSubscriptionAsync(topicName, subscriptionName); #endregion #region Snippet:UpdateTopic topic.UserMetadata = "some metadata"; TopicProperties updatedTopic = await client.UpdateTopicAsync(topic); #endregion Assert.AreEqual("some metadata", updatedTopic.UserMetadata); #region Snippet:UpdateSubscription subscription.UserMetadata = "some metadata"; SubscriptionProperties updatedSubscription = await client.UpdateSubscriptionAsync(subscription); #endregion Assert.AreEqual("some metadata", updatedSubscription.UserMetadata); // need to delete the subscription before the topic, as deleting // the topic would automatically delete the subscription #region Snippet:DeleteSubscription await client.DeleteSubscriptionAsync(topicName, subscriptionName); #endregion Assert.That( async() => await client.GetSubscriptionAsync(topicName, subscriptionName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusFailureReason.MessagingEntityNotFound)); #region Snippet:DeleteTopic await client.DeleteTopicAsync(topicName); #endregion Assert.That( async() => await client.GetTopicAsync(topicName), Throws.InstanceOf <ServiceBusException>().And.Property(nameof(ServiceBusException.Reason)).EqualTo(ServiceBusFailureReason.MessagingEntityNotFound)); }
public static async Task DeleteSubscription(string connectionString, string topic, string subscription) { var client = new ServiceBusAdministrationClient(connectionString); bool subscriptionExists = await client.SubscriptionExistsAsync(topic, subscription); if (subscriptionExists) { await client.DeleteSubscriptionAsync(topic, subscription); } }
protected async Task DeleteSubscriptionAsync(string subscription) { SubscriptionProperties existingSubscription = null; try { existingSubscription = await _serviceBusAdminClient.GetSubscriptionAsync(_topic, subscription); } catch { } if (existingSubscription is not null) { await _serviceBusAdminClient.DeleteSubscriptionAsync(_topic, subscription); } }
private Task DeleteSubscriptionAsync() => _serviceBusAdminClient.DeleteSubscriptionAsync(_createSubscriptionOptions.TopicName, _createSubscriptionOptions.SubscriptionName);
public static async Task <Azure.Response> DeleteSubscriptionAsync(string topicName, string connectionString, string subscriptionName) { var client = new ServiceBusAdministrationClient(connectionString); return(await client.DeleteSubscriptionAsync(topicName, subscriptionName)); }