private static async Task CreateTopic() { try { if (string.IsNullOrEmpty(namespaceName)) { throw new Exception("Namespace name is empty!"); } var token = await GetToken(); var creds = new TokenCredentials(token); var sbClient = new ServiceBusManagementClient(creds) { SubscriptionId = appOptions.SubscriptionId, }; var topicParams = new SBTopic { EnablePartitioning = true }; Console.WriteLine("Creating topic..."); await sbClient.Topics.CreateOrUpdateAsync(resourceGroupName, namespaceName, TopicName, topicParams); Console.WriteLine("Created topic successfully."); } catch (Exception e) { Console.WriteLine("Could not create a topic..."); Console.WriteLine(e.Message); throw e; } }
public PSTopicAttributes(SBTopic topicResource) { if (topicResource != null) { AccessedAt = topicResource.AccessedAt; AutoDeleteOnIdle = XmlConvert.ToString((TimeSpan)topicResource.AutoDeleteOnIdle); CreatedAt = topicResource.CreatedAt; CountDetails = topicResource.CountDetails; DefaultMessageTimeToLive = XmlConvert.ToString((TimeSpan)topicResource.DefaultMessageTimeToLive); DuplicateDetectionHistoryTimeWindow = XmlConvert.ToString((TimeSpan)topicResource.DuplicateDetectionHistoryTimeWindow); EnableBatchedOperations = topicResource.EnableBatchedOperations; EnableExpress = topicResource.EnableExpress; EnablePartitioning = topicResource.EnablePartitioning; MaxSizeInMegabytes = topicResource.MaxSizeInMegabytes; RequiresDuplicateDetection = topicResource.RequiresDuplicateDetection; SizeInBytes = topicResource.SizeInBytes; Status = topicResource.Status; SubscriptionCount = topicResource.SubscriptionCount; SupportOrdering = topicResource.SupportOrdering; UpdatedAt = topicResource.UpdatedAt; Name = topicResource.Name; Id = topicResource.Id; Type = topicResource.Type; } }
public async Task CreateTopic(string topicName) { try { using (var sbClient = await GetServiceManagementClient()) { var topicParams = new SBTopic { DefaultMessageTimeToLive = new TimeSpan(5, 0, 0, 0), MaxSizeInMegabytes = 1024, RequiresDuplicateDetection = false, EnablePartitioning = false, EnableBatchedOperations = false, EnableExpress = false }; await sbClient.Topics.CreateOrUpdateAsync(appOptions.ResourceGroupName, appOptions.NamespaceName, topicName, topicParams); } } catch (Exception e) { Console.WriteLine("Could not create a topic..."); Console.WriteLine(e.Message); throw e; } }
public TopicAttributes(SBTopic topicResource) { if (topicResource != null) { AccessedAt = topicResource.AccessedAt; AutoDeleteOnIdle = XmlConvert.ToString((TimeSpan)topicResource.AutoDeleteOnIdle); CreatedAt = topicResource.CreatedAt; CountDetails = topicResource.CountDetails; DefaultMessageTimeToLive = XmlConvert.ToString((TimeSpan)topicResource.DefaultMessageTimeToLive); DuplicateDetectionHistoryTimeWindow = XmlConvert.ToString((TimeSpan)topicResource.DuplicateDetectionHistoryTimeWindow); EnableBatchedOperations = topicResource.EnableBatchedOperations; EnableExpress = topicResource.EnableExpress; EnablePartitioning = topicResource.EnablePartitioning; MaxSizeInMegabytes = topicResource.MaxSizeInMegabytes; RequiresDuplicateDetection = topicResource.RequiresDuplicateDetection; SizeInBytes = topicResource.SizeInBytes; Status = topicResource.Status; SubscriptionCount = topicResource.SubscriptionCount; SupportOrdering = topicResource.SupportOrdering; UpdatedAt = topicResource.UpdatedAt; Name = topicResource.Name; Id = topicResource.Id; Type = topicResource.Type; #pragma warning disable 612, 618 EnableSubscriptionPartitioning = false; FilteringMessagesBeforePublishing = false; IsAnonymousAccessible = false; IsExpress = false; EntityAvailabilityStatus = "Available"; Location = ""; #pragma warning restore 612, 618 } }
/// <summary> /// Creates a Service Bus scope associated with a topic instance, intended to be used in the context /// of a single test and disposed when the test has completed. /// </summary> /// /// <param name="enablePartitioning">When <c>true</c>, partitioning will be enabled on the topic that is created.</param> /// <param name="enableSession">When <c>true</c>, a session will be enabled on the topic that is created.</param> /// <param name="topicSubscriptions">The set of subscriptions to create for the topic. If <c>null</c>, a default subscription will be assumed.</param> /// <param name="forceTopicCreation">When <c>true</c>, forces creation of a new topic even if an environmental override was specified to use an existing one.</param> /// <param name="caller">The name of the calling method; this is intended to be populated by the runtime.</param> /// /// <returns>The requested Service Bus <see cref="TopicScope" />.</returns> /// /// <remarks> /// If an environmental override was set to use an existing Service Bus queue resource and the <paramref name="forceTopicCreation" /> flag /// was not set, the existing queue will be assumed with no validation. In this case the <paramref name="enablePartitioning" />, /// <paramref name="enableSession" />, and <paramref name="topicSubscriptions" /> parameters are also ignored. /// </remarks> /// public static async Task <TopicScope> CreateWithTopic(bool enablePartitioning, bool enableSession, IEnumerable <string> topicSubscriptions = null, bool forceTopicCreation = false, [CallerMemberName] string caller = "") { caller = (caller.Length < 16) ? caller : caller.Substring(0, 15); topicSubscriptions ??= new[] { "default-subscription" }; var azureSubscription = ServiceBusTestEnvironment.Instance.SubscriptionId; var resourceGroup = ServiceBusTestEnvironment.Instance.ResourceGroup; var serviceBusNamespace = ServiceBusTestEnvironment.Instance.ServiceBusNamespace; var token = await AquireManagementTokenAsync().ConfigureAwait(false); using (var client = new ServiceBusManagementClient(ResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = azureSubscription }) { // If there was an override and the force flag is not set for creation, then build a scope for the // specified topic. Query the topic resource to build the list of its subscriptions for the scope. if ((!string.IsNullOrEmpty(ServiceBusTestEnvironment.Instance.OverrideTopicName)) && (!forceTopicCreation)) { var subscriptionPage = await CreateRetryPolicy <IPage <SBSubscription> >().ExecuteAsync(() => client.Subscriptions.ListByTopicAsync(resourceGroup, serviceBusNamespace, ServiceBusTestEnvironment.Instance.OverrideTopicName)).ConfigureAwait(false); var existingSubscriptions = new List <string>(subscriptionPage.Select(item => item.Name)); while (!string.IsNullOrEmpty(subscriptionPage.NextPageLink)) { subscriptionPage = await CreateRetryPolicy <IPage <SBSubscription> >().ExecuteAsync(() => client.Subscriptions.ListByTopicAsync(resourceGroup, serviceBusNamespace, ServiceBusTestEnvironment.Instance.OverrideTopicName)).ConfigureAwait(false); existingSubscriptions.AddRange(subscriptionPage.Select(item => item.Name)); } return(new TopicScope(ServiceBusTestEnvironment.Instance.ServiceBusNamespace, ServiceBusTestEnvironment.Instance.OverrideTopicName, existingSubscriptions, false)); } // Create a new topic specific for the scope being created. string CreateName() => $"{ Guid.NewGuid().ToString("D").Substring(0, 13) }-{ caller }"; var duplicateDetection = TimeSpan.FromMinutes(10); var topicParameters = new SBTopic(enablePartitioning: enablePartitioning, duplicateDetectionHistoryTimeWindow: duplicateDetection, maxSizeInMegabytes: 1024); var topic = await CreateRetryPolicy <SBTopic>().ExecuteAsync(() => client.Topics.CreateOrUpdateAsync(resourceGroup, serviceBusNamespace, CreateName(), topicParameters)).ConfigureAwait(false); var subscriptionParams = new SBSubscription(requiresSession: enableSession, duplicateDetectionHistoryTimeWindow: duplicateDetection, maxDeliveryCount: 10); var activeSubscriptions = await Task.WhenAll ( topicSubscriptions.Select(subscriptionName => CreateRetryPolicy <SBSubscription>().ExecuteAsync(() => client.Subscriptions.CreateOrUpdateAsync(resourceGroup, serviceBusNamespace, topic.Name, subscriptionName, subscriptionParams))) ).ConfigureAwait(false); return(new TopicScope(serviceBusNamespace, topic.Name, activeSubscriptions.Select(item => item.Name).ToList(), true)); } }
public async Task <TopicClient> CreateTopicAsync(string topicName) { var serviceBusManagementClient = await CreateServiceBusManagementClientAsync(); var parameters = new SBTopic(); await serviceBusManagementClient.Topics.CreateOrUpdateAsync(_configuration.ResourceGroupName, _configuration.ServiceBusName, topicName, parameters); return(new TopicClient(connectionString: _configuration.ConnectionString, entityPath: topicName)); }
public PSTopicAttributes UpdateTopic(string resourceGroupName, string namespaceName, string topicName, string location, bool enableExpress, bool isAnonymousAccessible) { SBTopic parameters = new SBTopic() { EnableExpress = enableExpress }; var response = Client.Topics.CreateOrUpdate(resourceGroupName, namespaceName, topicName, parameters); return(new PSTopicAttributes(response)); }
public PSTopicAttributes CreateUpdateTopic(string resourceGroupName, string namespaceName, string topicName, PSTopicAttributes topic) { var parameters = new SBTopic(); if (topic.AutoDeleteOnIdle != null) { parameters.AutoDeleteOnIdle = (TimeSpan?)AzureServiceBusCmdletBase.ParseTimespan(topic.AutoDeleteOnIdle); } if (topic.DefaultMessageTimeToLive != null) { parameters.DefaultMessageTimeToLive = (TimeSpan?)AzureServiceBusCmdletBase.ParseTimespan(topic.DefaultMessageTimeToLive); } if (topic.DuplicateDetectionHistoryTimeWindow != null) { parameters.DuplicateDetectionHistoryTimeWindow = (TimeSpan?)AzureServiceBusCmdletBase.ParseTimespan(topic.DuplicateDetectionHistoryTimeWindow); } if (topic.EnableBatchedOperations != null) { parameters.EnableBatchedOperations = topic.EnableBatchedOperations; } if (topic.EnableExpress != null) { parameters.EnableExpress = topic.EnableExpress; } if (topic.EnablePartitioning != null) { parameters.EnablePartitioning = topic.EnablePartitioning; } if (topic.MaxSizeInMegabytes != null) { parameters.MaxSizeInMegabytes = topic.MaxSizeInMegabytes; } if (topic.RequiresDuplicateDetection != null) { parameters.RequiresDuplicateDetection = topic.RequiresDuplicateDetection; } if (topic.Status != null) { parameters.Status = topic.Status; } if (topic.SupportOrdering != null) { parameters.SupportOrdering = topic.SupportOrdering; } var response = Client.Topics.CreateOrUpdate(resourceGroupName, namespaceName, topicName, parameters); return(new PSTopicAttributes(response)); }
private async Task EnsureTopic() { var context = new AuthenticationContext($"https://login.microsoftonline.com/{_tenantId}"); var token = await context.AcquireTokenAsync("https://management.azure.com/", new ClientCredential(_clientId, _clientSecret)); var creds = new TokenCredentials(token.AccessToken); var sbClient = new ServiceBusManagementClient(creds) { SubscriptionId = _subscriptionId }; var topicParams = new SBTopic() { EnableExpress = _enableExpress, EnableBatchedOperations = _enableBatchOperations }; await sbClient.Topics.CreateOrUpdateAsync(_resourceGroup, _namespaceName, _topicName, topicParams); }
internal async Task CreateTopic(ServiceBusTopicModel model) { await EnsureAuthenticatedAsync(); Trace.WriteLine($"Create topic: {model.CreatedName}"); var pars = new SBTopic() { AutoDeleteOnIdle = TimeSpan.FromMinutes(30) }; SBTopic topic = _client.Topics.CreateOrUpdate( _identifier.ResourceGroupName, _identifier.Name, model.CreatedName, pars); foreach (ServiceBusSubscriptionModel sub in model.Subscriptions) { await CreateSubscription(topic.Name, sub); } }
/// <summary> /// Creates a Service Bus scope associated with a topic instance, intended to be used in the context /// of a single test and disposed when the test has completed. /// </summary> /// /// <param name="enablePartitioning">When <c>true</c>, partitioning will be enabled on the topic that is created.</param> /// <param name="enableSession">When <c>true</c>, a session will be enabled on the topic that is created.</param> /// <param name="topicSubscriptions">The set of subscriptions to create for the topic. If <c>null</c>, a default subscription will be assumed.</param> /// <param name="forceTopicCreation">When <c>true</c>, forces creation of a new topic even if an environmental override was specified to use an existing one.</param> /// <param name="caller">The name of the calling method; this is intended to be populated by the runtime.</param> /// /// <returns>The requested Service Bus <see cref="TopicScope" />.</returns> /// /// <remarks> /// If an environmental override was set to use an existing Service Bus queue resource and the <paramref name="forceTopicCreation" /> flag /// was not set, the existing queue will be assumed with no validation. In this case the <paramref name="enablePartitioning" />, /// <paramref name="enableSession" />, and <paramref name="topicSubscriptions" /> parameters are also ignored. /// </remarks> /// public static async Task <TopicScope> CreateWithTopic(bool enablePartitioning, bool enableSession, IEnumerable <string> topicSubscriptions = null, bool forceTopicCreation = false, [CallerMemberName] string caller = "") { caller = (caller.Length < 16) ? caller : caller.Substring(0, 15); topicSubscriptions ??= new[] { "default-subscription" }; var azureSubscription = ServiceBusTestEnvironment.Instance.SubscriptionId; var resourceGroup = ServiceBusTestEnvironment.Instance.ResourceGroup; var serviceBusNamespace = ServiceBusTestEnvironment.Instance.ServiceBusNamespace; var token = await AcquireManagementTokenAsync().ConfigureAwait(false); using (var client = new ServiceBusManagementClient(ResourceManagerUri, new TokenCredentials(token)) { SubscriptionId = azureSubscription }) { // Create a new topic specific for the scope being created. string CreateName() => $"{ Guid.NewGuid().ToString("D").Substring(0, 13) }-{ caller }"; var duplicateDetection = TimeSpan.FromMinutes(10); var topicParameters = new SBTopic(enablePartitioning: enablePartitioning, duplicateDetectionHistoryTimeWindow: duplicateDetection, maxSizeInMegabytes: 1024); var topic = await CreateRetryPolicy <SBTopic>().ExecuteAsync(() => client.Topics.CreateOrUpdateAsync(resourceGroup, serviceBusNamespace, CreateName(), topicParameters)).ConfigureAwait(false); var subscriptionParams = new SBSubscription(requiresSession: enableSession, duplicateDetectionHistoryTimeWindow: duplicateDetection, maxDeliveryCount: 10); var activeSubscriptions = await Task.WhenAll ( topicSubscriptions.Select(subscriptionName => CreateRetryPolicy <SBSubscription>().ExecuteAsync(() => client.Subscriptions.CreateOrUpdateAsync(resourceGroup, serviceBusNamespace, topic.Name, subscriptionName, subscriptionParams))) ).ConfigureAwait(false); return(new TopicScope(serviceBusNamespace, topic.Name, activeSubscriptions.Select(item => item.Name).ToList(), true)); } }
public PSTopicAttributes GetTopic(string resourceGroupName, string namespaceName, string topicName) { SBTopic response = Client.Topics.Get(resourceGroupName, namespaceName, topicName); return(new PSTopicAttributes(response)); }
private SBTopic CreateTopicDescription() { var td = new SBTopic(_options.Topic); if (_options.TopicAutoDeleteOnIdle.HasValue) { td.AutoDeleteOnIdle = _options.TopicAutoDeleteOnIdle.Value; } if (_options.TopicDefaultMessageTimeToLive.HasValue) { td.DefaultMessageTimeToLive = _options.TopicDefaultMessageTimeToLive.Value; } if (_options.TopicMaxSizeInMegabytes.HasValue) { td.MaxSizeInMegabytes = Convert.ToInt32(_options.TopicMaxSizeInMegabytes.Value); } if (_options.TopicRequiresDuplicateDetection.HasValue) { td.RequiresDuplicateDetection = _options.TopicRequiresDuplicateDetection.Value; } if (_options.TopicDuplicateDetectionHistoryTimeWindow.HasValue) { td.DuplicateDetectionHistoryTimeWindow = _options.TopicDuplicateDetectionHistoryTimeWindow.Value; } if (_options.TopicEnableBatchedOperations.HasValue) { td.EnableBatchedOperations = _options.TopicEnableBatchedOperations.Value; } //if (_options.TopicEnableFilteringMessagesBeforePublishing.HasValue) // td.EnableFilteringMessagesBeforePublishing = _options.TopicEnableFilteringMessagesBeforePublishing.Value; //if (_options.TopicIsAnonymousAccessible.HasValue) // td.IsAnonymousAccessible = _options.TopicIsAnonymousAccessible.Value; if (_options.TopicStatus.HasValue) { td.Status = _options.TopicStatus.Value; } if (_options.TopicSupportOrdering.HasValue) { td.SupportOrdering = _options.TopicSupportOrdering.Value; } if (_options.TopicEnablePartitioning.HasValue) { td.EnablePartitioning = _options.TopicEnablePartitioning.Value; } if (_options.TopicEnableExpress.HasValue) { td.EnableExpress = _options.TopicEnableExpress.Value; } //if (!String.IsNullOrEmpty(_options.TopicUserMetadata)) // td.UserMetadata = _options.TopicUserMetadata; return(td); }
/// <summary> /// Creates a topic in the specified namespace. /// <see href="https://msdn.microsoft.com/en-us/library/azure/mt639409.aspx" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the Resource group within the Azure subscription. /// </param> /// <param name='namespaceName'> /// The namespace name /// </param> /// <param name='topicName'> /// The topic name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a topic resource. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <SBTopic> CreateOrUpdateAsync(this ITopicsOperations operations, string resourceGroupName, string namespaceName, string topicName, SBTopic parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, namespaceName, topicName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a topic in the specified namespace. /// <see href="https://msdn.microsoft.com/en-us/library/azure/mt639409.aspx" /> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the Resource group within the Azure subscription. /// </param> /// <param name='namespaceName'> /// The namespace name /// </param> /// <param name='topicName'> /// The topic name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a topic resource. /// </param> public static SBTopic CreateOrUpdate(this ITopicsOperations operations, string resourceGroupName, string namespaceName, string topicName, SBTopic parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, namespaceName, topicName, parameters).GetAwaiter().GetResult()); }
/// <summary> /// Set this to create if the service bus topic does not exist for publish and sending. /// Service Bus topic name, RockyBus, should be created manually, /// there should be a single owner to avoid inconsistent creation, /// or there should be a shared way to creating the service bus topic. This is still questionable based on fragileness of topic creation. /// </summary> public PublishAndSendOptions AttemptCreateTopicWith(SBTopic sbTopic) { SBTopic = sbTopic; return(this); }
public void TopicsCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(ServiceBusManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(ServiceBusManagementHelper.NamespacePrefix); var createNamespaceResponse = this.ServiceBusManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new SBNamespace() { Location = location, Sku = new SBSku { Name = SkuName.Standard, Tier = SkuTier.Standard } }); Assert.NotNull(createNamespaceResponse); Assert.Equal(createNamespaceResponse.Name, namespaceName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Create a Topic var topicName = TestUtilities.GenerateName(ServiceBusManagementHelper.TopicPrefix); var createTopicResponse = this.ServiceBusManagementClient.Topics.CreateOrUpdate(resourceGroup, namespaceName, topicName, new SBTopic() { EnableExpress = true }); Assert.NotNull(createTopicResponse); Assert.Equal(createTopicResponse.Name, topicName); // Get the created topic var getTopicResponse = ServiceBusManagementClient.Topics.Get(resourceGroup, namespaceName, topicName); Assert.NotNull(getTopicResponse); Assert.Equal(EntityStatus.Active, getTopicResponse.Status); Assert.Equal(getTopicResponse.Name, topicName); // Get all Topics var getTopicsListAllResponse = ServiceBusManagementClient.Topics.ListByNamespace(resourceGroup, namespaceName); Assert.NotNull(getTopicsListAllResponse); Assert.True(getTopicsListAllResponse.Count() >= 1); Assert.True(getTopicsListAllResponse.All(ns => ns.Id.Contains(resourceGroup))); // Update Topic var updateTopicsParameter = new SBTopic() { EnableExpress = true }; var updateTopicsResponse = ServiceBusManagementClient.Topics.CreateOrUpdate(resourceGroup, namespaceName, topicName, updateTopicsParameter); Assert.NotNull(updateTopicsResponse); Assert.True(updateTopicsResponse.EnableExpress); Assert.NotEqual(updateTopicsResponse.UpdatedAt, getTopicResponse.UpdatedAt); // Get the created topic to check the Updated values. getTopicResponse = ServiceBusManagementClient.Topics.Get(resourceGroup, namespaceName, topicName); Assert.NotNull(getTopicResponse); Assert.Equal(EntityStatus.Active, getTopicResponse.Status); Assert.Equal(getTopicResponse.Name, topicName); Assert.True(updateTopicsResponse.EnableExpress); Assert.NotEqual(updateTopicsResponse.UpdatedAt, getTopicResponse.UpdatedAt); // Delete Created Topics ServiceBusManagementClient.Topics.Delete(resourceGroup, namespaceName, topicName); // Delete namespace ServiceBusManagementClient.Namespaces.Delete(resourceGroup, namespaceName); } }