Esempio n. 1
0
        private async Task ProvisionTopicAsync(ServiceBus manager, string topicName, bool keepOperationPending = false)
        {
            if (!(await manager.TopicExistsAsync(topicName)))
            {
                _logger.LogDebug($"Provisioning topic: '{topicName}'");

                // TODO :: Implement retry policies
                try
                {
                    await manager.CreateTopicAsync(new TopicDescription(topicName)
                    {
                        AutoDeleteOnIdle         = _options.AutoDeleteOnIdle,
                        DefaultMessageTimeToLive = _options.MessageTimeToLive,
                        EnableBatchedOperations  = _options.EnableServerSideBatchedOperations,
                        EnableExpress            = _options.EnableExpress,
                        EnablePartitioning       = _options.EnablePartitioning
                    });

                    _logger.LogInformation($"Provisioned topic: '{topicName}'");
                }
                catch (Exception ex)
                {
                    _logger.LogError($"An error occured whilst provisioning topic: '{topicName}'", ex);
                }
            }
            else
            {
                _logger.LogDebug($"Topic '{topicName}' already exists, no need to provision.");
            }

            if (!keepOperationPending)
            {
                RemoveOperation(topicName);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if a topic by the provided <paramref name="topicName"/> exists and
        /// Checks if a subscription name by the provided <paramref name="subscriptionName"/> exists.
        /// </summary>
        protected virtual void CheckTopicExists(Manager manager, string topicName, string subscriptionName)
        {
            // Configure Queue Settings
            var eventTopicDescription = new TopicDescription(topicName)
            {
#if NET452
                MaxSizeInMegabytes = 5120,
#endif
#if NETSTANDARD2_0
                MaxSizeInMB = 5120,
#endif
                DefaultMessageTimeToLive = new TimeSpan(0, 25, 0),
                EnablePartitioning       = true,
                EnableBatchedOperations  = true,
            };

#if NETSTANDARD2_0
            Task <bool> checkTask = manager.TopicExistsAsync(topicName);
            checkTask.Wait(1500);
            if (!checkTask.Result)
            {
                Task <TopicDescription> createTopicTask = manager.CreateTopicAsync(eventTopicDescription);
                createTopicTask.Wait(1500);
            }

            checkTask = manager.SubscriptionExistsAsync(topicName, subscriptionName);
            checkTask.Wait(1500);
            if (!checkTask.Result)
            {
                var subscriptionDescription = new SubscriptionDescription(topicName, subscriptionName)
                {
                    DefaultMessageTimeToLive = eventTopicDescription.DefaultMessageTimeToLive,
                    EnableBatchedOperations  = eventTopicDescription.EnableBatchedOperations,
                };
                Task <SubscriptionDescription> createTask = manager.CreateSubscriptionAsync(subscriptionDescription);
                createTask.Wait(1500);
            }
#endif

#if NET452
            // Create the topic if it does not exist already
            if (!manager.TopicExists(eventTopicDescription.Path))
            {
                manager.CreateTopic(eventTopicDescription);
            }

            if (!manager.SubscriptionExists(eventTopicDescription.Path, subscriptionName))
            {
                manager.CreateSubscription
                (
                    new SubscriptionDescription(eventTopicDescription.Path, subscriptionName)
                {
                    DefaultMessageTimeToLive = new TimeSpan(0, 25, 0),
                    EnableBatchedOperations  = true,
                    EnableDeadLetteringOnFilterEvaluationExceptions = true
                }
                );
            }
#endif
        }