示例#1
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
        }
示例#2
0
        /// <summary>
        /// Checks if a event hub by the provided <paramref name="hubName"/> exists and
        /// Checks if a consumer group by the provided <paramref name="consumerGroupNames"/> exists.
        /// </summary>
        protected virtual void CheckHubExists(Manager manager, string hubName, string consumerGroupNames)
        {
#if NET452
            // Configure Queue Settings
            var eventHubDescription = new EventHubDescription(hubName)
            {
                MessageRetentionInDays = long.MaxValue,
            };

            // Create the topic if it does not exist already
            manager.CreateEventHubIfNotExists(eventHubDescription);

            var subscriptionDescription = new SubscriptionDescription(eventHubDescription.Path, consumerGroupNames);

            if (!manager.SubscriptionExists(eventHubDescription.Path, consumerGroupNames))
            {
                manager.CreateSubscription(subscriptionDescription);
            }
#endif
#if NETSTANDARD2_0
            /*
             * // Configure Queue Settings
             * var eventHubDescription = new EventHubDescription(hubName)
             * {
             *      MessageRetentionInDays = long.MaxValue,
             * };
             *
             * // Create the topic if it does not exist already
             * manager.CreateEventHubIfNotExists(eventHubDescription);
             *
             * Task<bool> checkTask = manager.SubscriptionExistsAsync(eventHubDescription.Path, consumerGroupNames);
             * checkTask.Wait(1500);
             * if (!checkTask.Result)
             *      manager.CreateSubscriptionAsync(subscriptionDescription).Wait(1500);
             */
            Logger.LogWarning($"Checking EventHubs and subscriptions is not currently implemented until the Azure libraries provide management facilities. You will need to check these objects exist manually: EventHub {hubName}, Subscription/Consumer Group {consumerGroupNames}", "AzureEventHub");
#endif
        }