Esempio n. 1
0
        private async Task ProvisionSubscriptionAsync(ServiceBus manager, string topicName, string subscriptionName)
        {
            await ProvisionTopicAsync(manager, topicName, true);

            if (!(await manager.SubscriptionExistsAsync(topicName, subscriptionName)))
            {
                _logger.LogDebug($"Provisioning subscription: '{topicName}/{subscriptionName}'");

                // TODO :: Implement retry policies
                try
                {
                    await manager.CreateSubscriptionAsync(new SubscriptionDescription(topicName, subscriptionName)
                    {
                        AutoDeleteOnIdle         = _options.AutoDeleteOnIdle,
                        DefaultMessageTimeToLive = _options.MessageTimeToLive,
                        EnableBatchedOperations  = _options.EnableServerSideBatchedOperations,
                        LockDuration             = _options.MessageLockDuration,
                        MaxDeliveryCount         = _options.MaximumDeliveryCount
                    });

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

            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
        }