Ejemplo n.º 1
0
        private static void UpdateRules(NamespaceManager namespaceManager, TopicSettings topic, SubscriptionSettings subscription)
        {
            string sqlExpression = null;

            if (!string.IsNullOrWhiteSpace(subscription.SqlFilter))
            {
                sqlExpression = subscription.SqlFilter;
            }

            UpdateSqlFilter(namespaceManager, sqlExpression, subscription.Name, topic.Path);
        }
Ejemplo n.º 2
0
        private void CreateTopicIfNotExists(NamespaceManager namespaceManager, TopicSettings topic)
        {
            var topicDescription =
                new TopicDescription(topic.Path)
            {
                RequiresDuplicateDetection          = true,
                DuplicateDetectionHistoryTimeWindow = topic.DuplicateDetectionHistoryTimeWindow
            };

            try {
                namespaceManager.CreateTopic(topicDescription);
            } catch (MessagingEntityAlreadyExistsException) { }
        }
        private void CreateTopicIfNotExists(NamespaceManager namespaceManager, TopicSettings topic)
        {
            var topicDescription =
                new TopicDescription(topic.Path)
                {
                    RequiresDuplicateDetection = true,
                    DuplicateDetectionHistoryTimeWindow = topic.DuplicateDetectionHistoryTimeWindow,
                };

            try
            {
                namespaceManager.CreateTopic(topicDescription);
            }
            catch (MessagingEntityAlreadyExistsException) { }
        }
        private void CreateSubscriptionIfNotExists(NamespaceManager namespaceManager, TopicSettings topic, SubscriptionSettings subscription)
        {
            var subscriptionDescription =
                new SubscriptionDescription(topic.Path, subscription.Name)
                {
                    RequiresSession = subscription.RequiresSession
                };

            try
            {
                namespaceManager.CreateSubscription(subscriptionDescription);
            }
            catch (MessagingEntityAlreadyExistsException) { }
        }
Ejemplo n.º 5
0
        private static void CreateTopicIfNotExists(NamespaceManager namespaceManager, TopicSettings topicSettings)
        {
            if (namespaceManager.TopicExists(topicSettings.Path))
            {
                return;
            }

            var topicDescription = new TopicDescription(topicSettings.Path)
            {
                // Fill topic settings;
            };

            namespaceManager.CreateTopic(topicDescription);
        }
Ejemplo n.º 6
0
        public EventProcessor CreateEventProcessor(string subscription, IEventHandler handler, ITextSerializer serializer, bool instrumentationEnabled = false)
        {
            if (!this.initialized)
            {
                throw new InvalidOperationException("Service bus configuration has not been initialized.");
            }

            TopicSettings        topicSettings        = null;
            SubscriptionSettings subscriptionSettings = null;

            foreach (var settings in this.settings.Topics.Where(t => t.IsEventBus))
            {
                subscriptionSettings = settings.Subscriptions.Find(s => s.Name == subscription);
                if (subscriptionSettings != null)
                {
                    topicSettings = settings;
                    break;
                }
            }

            if (subscriptionSettings == null)
            {
                throw new ArgumentOutOfRangeException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              "Subscription '{0}' has not been registered for an event bus topic in the service bus configuration.",
                              subscription));
            }

            IMessageReceiver receiver;

            if (subscriptionSettings.RequiresSession)
            {
                var instrumentation = new SessionSubscriptionReceiverInstrumentation(subscription, instrumentationEnabled);
                try
                {
                    receiver = (IMessageReceiver) new SessionSubscriptionReceiver(this.settings, topicSettings.Path, subscription, true, instrumentation);
                }
                catch
                {
                    instrumentation.Dispose();
                    throw;
                }
            }
            else
            {
                var instrumentation = new SubscriptionReceiverInstrumentation(subscription, instrumentationEnabled);
                try
                {
                    receiver = (IMessageReceiver) new SubscriptionReceiver(this.settings, topicSettings.Path, subscription, true, instrumentation);
                }
                catch
                {
                    instrumentation.Dispose();
                    throw;
                }
            }

            EventProcessor processor;

            try
            {
                processor = new EventProcessor(receiver, serializer);
            }
            catch
            {
                using (receiver as IDisposable) { }
                throw;
            }

            try
            {
                processor.Register(handler);

                return(processor);
            }
            catch
            {
                processor.Dispose();
                throw;
            }
        }
Ejemplo n.º 7
0
        private static void UpdateSubscriptionIfExists(NamespaceManager namespaceManager, TopicSettings topic, UpdateSubscriptionIfExists action)
        {
            if (string.IsNullOrWhiteSpace(action.Name))
            {
                throw new ArgumentException("action");
            }
            if (string.IsNullOrWhiteSpace(action.SqlFilter))
            {
                throw new ArgumentException("action");
            }

            UpdateSqlFilter(namespaceManager, action.SqlFilter, action.Name, topic.Path);
        }
Ejemplo n.º 8
0
        private void CreateSubscriptionIfNotExists(NamespaceManager namespaceManager, TopicSettings topic, SubscriptionSettings subscription)
        {
            var subscriptionDescription =
                new SubscriptionDescription(topic.Path, subscription.Name)
            {
                RequiresSession = subscription.RequiresSession,
                LockDuration    = TimeSpan.FromSeconds(150),
            };

            try
            {
                namespaceManager.CreateSubscription(subscriptionDescription);
            }
            catch (MessagingEntityAlreadyExistsException) { }
        }
Ejemplo n.º 9
0
        private static void UpdateRules(NamespaceManager namespaceManager, TopicSettings topic, SubscriptionSettings subscription)
        {
            string sqlExpression = null;
            if (!string.IsNullOrWhiteSpace(subscription.SqlFilter))
            {
                sqlExpression = subscription.SqlFilter;
            }

            UpdateSqlFilter(namespaceManager, sqlExpression, subscription.Name, topic.Path);
        }
Ejemplo n.º 10
0
        private static void UpdateSubscriptionIfExists(NamespaceManager namespaceManager, TopicSettings topic, UpdateSubscriptionIfExists action)
        {
            if (string.IsNullOrWhiteSpace(action.Name)) throw new ArgumentException("action");
            if (string.IsNullOrWhiteSpace(action.SqlFilter)) throw new ArgumentException("action");

            UpdateSqlFilter(namespaceManager, action.SqlFilter, action.Name, topic.Path);
        }