コード例 #1
0
        public void When_registered_registering_multiple_addresses_for_same_type_same_number_of_addresses_are_returned()
        {
            var baseType = typeof(BaseMessage);
            var router   = new StaticMessageRouter(Enumerable.Empty <Type>());
            var addressA = new Address("BaseMessage", "A");

            router.RegisterEventRoute(baseType, addressA);
            var addressB = new Address("BaseMessage", "b");

            router.RegisterEventRoute(baseType, addressB);

            Assert.AreEqual(2, router.GetDestinationFor(baseType).Count);
        }
コード例 #2
0
 public void When_inherited_base_after_registered_correct_address_is_returned_for_both()
 {
     var baseType = typeof(BaseMessage);
     var inheritedType = typeof(InheritedMessage);
     var router = new StaticMessageRouter(new[]
     {
         baseType,
         inheritedType
     });
     var inheritedAddress = new Address("inheritedAddress", "b");
     router.RegisterEventRoute(inheritedType, inheritedAddress);
     var baseAddress = new Address("baseAddress", "b");
     router.RegisterEventRoute(baseType, baseAddress);
     Assert.Contains(baseAddress, router.GetDestinationFor(baseType));
     Assert.Contains(inheritedAddress, router.GetDestinationFor(baseType));
     Assert.AreSame(inheritedAddress, router.GetDestinationFor(inheritedType).Single());
 }
コード例 #3
0
        public void When_inherited_base_after_registered_correct_address_is_returned_for_both()
        {
            var baseType      = typeof(BaseMessage);
            var inheritedType = typeof(InheritedMessage);
            var router        = new StaticMessageRouter(new[]
            {
                baseType,
                inheritedType
            });
            var inheritedAddress = new Address("inheritedAddress", "b");

            router.RegisterEventRoute(inheritedType, inheritedAddress);
            var baseAddress = new Address("baseAddress", "b");

            router.RegisterEventRoute(baseType, baseAddress);
            Assert.Contains(baseAddress, router.GetDestinationFor(baseType));
            Assert.Contains(inheritedAddress, router.GetDestinationFor(baseType));
            Assert.AreSame(inheritedAddress, router.GetDestinationFor(inheritedType).Single());
        }
コード例 #4
0
        void RegisterMessageOwnersAndBusAddress(FeatureConfigurationContext context, IEnumerable <Type> knownMessages)
        {
            var unicastConfig = context.Settings.GetConfigSection <UnicastBusConfig>();
            var router        = new StaticMessageRouter(knownMessages);
            var key           = typeof(AutoSubscriptionStrategy).FullName + ".SubscribePlainMessages";

            if (context.Settings.HasSetting(key))
            {
                router.SubscribeToPlainMessages = context.Settings.Get <bool>(key);
            }

            context.Container.RegisterSingleton(router);

            if (unicastConfig == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo))
            {
                var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo);
                context.Container.ConfigureProperty <ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress);
            }

            if (unicastConfig.TimeToBeReceivedOnForwardedMessages != TimeSpan.Zero)
            {
                context.Container.ConfigureProperty <ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages);
            }

            var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast <MessageEndpointMapping>()
                                          .OrderByDescending(m => m)
                                          .ToList();

            foreach (var mapping in messageEndpointMappings)
            {
                mapping.Configure((messageType, address) =>
                {
                    var conventions = context.Settings.Get <Conventions>();
                    if (!(conventions.IsMessageType(messageType) || conventions.IsEventType(messageType) || conventions.IsCommandType(messageType)))
                    {
                        return;
                    }

                    if (conventions.IsEventType(messageType))
                    {
                        router.RegisterEventRoute(messageType, address);
                        return;
                    }

                    router.RegisterMessageRoute(messageType, address);
                });
            }
        }
コード例 #5
0
        void RegisterMessageOwnersAndBusAddress(IEnumerable <Type> knownMessages)
        {
            var unicastConfig = Configure.GetConfigSection <UnicastBusConfig>();
            var router        = new StaticMessageRouter(knownMessages);
            var key           = typeof(DefaultAutoSubscriptionStrategy).FullName + ".SubscribePlainMessages";

            if (SettingsHolder.HasSetting(key))
            {
                router.SubscribeToPlainMessages = SettingsHolder.Get <bool>(key);
            }

            Configure.Instance.Configurer.RegisterSingleton <StaticMessageRouter>(router);

            if (unicastConfig == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo))
            {
                var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo);
                Configure.Instance.Configurer.ConfigureProperty <UnicastBus>(b => b.ForwardReceivedMessagesTo,
                                                                             forwardAddress);
                Configure.Instance.Configurer.ConfigureProperty <ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress);
            }
            Configure.Instance.Configurer.ConfigureProperty <UnicastBus>(b => b.TimeToBeReceivedOnForwardedMessages,
                                                                         unicastConfig.TimeToBeReceivedOnForwardedMessages);
            Configure.Instance.Configurer.ConfigureProperty <ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages);

            var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast <MessageEndpointMapping>()
                                          .OrderByDescending(m => m)
                                          .ToList();

            foreach (var mapping in messageEndpointMappings)
            {
                mapping.Configure((messageType, address) =>
                {
                    if (!(MessageConventionExtensions.IsMessageType(messageType) || MessageConventionExtensions.IsEventType(messageType) || MessageConventionExtensions.IsCommandType(messageType)))
                    {
                        return;
                    }

                    if (MessageConventionExtensions.IsEventType(messageType))
                    {
                        router.RegisterEventRoute(messageType, address);
                        return;
                    }

                    router.RegisterMessageRoute(messageType, address);
                });
            }
        }
コード例 #6
0
        void RegisterMessageOwnersAndBusAddress(IEnumerable<Type> knownMessages)
        {
            var unicastConfig = Configure.GetConfigSection<UnicastBusConfig>();
            var router = new StaticMessageRouter(knownMessages);
            var key = typeof(DefaultAutoSubscriptionStrategy).FullName + ".SubscribePlainMessages";

            if (SettingsHolder.HasSetting(key))
            {
                router.SubscribeToPlainMessages = SettingsHolder.Get<bool>(key);
            }

            Configure.Instance.Configurer.RegisterSingleton<StaticMessageRouter>(router);

            if (unicastConfig == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo))
            {
                var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo);
                Configure.Instance.Configurer.ConfigureProperty<UnicastBus>(b => b.ForwardReceivedMessagesTo,
                    forwardAddress);
                Configure.Instance.Configurer.ConfigureProperty<ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress);
            }
            Configure.Instance.Configurer.ConfigureProperty<UnicastBus>(b => b.TimeToBeReceivedOnForwardedMessages,
                unicastConfig.TimeToBeReceivedOnForwardedMessages);
            Configure.Instance.Configurer.ConfigureProperty<ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages);

            var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast<MessageEndpointMapping>()
                .OrderByDescending(m => m)
                .ToList();

            foreach (var mapping in messageEndpointMappings)
            {
                mapping.Configure((messageType, address) =>
                {
                    if (!(MessageConventionExtensions.IsMessageType(messageType) || MessageConventionExtensions.IsEventType(messageType) || MessageConventionExtensions.IsCommandType(messageType)))
                    {
                        return;
                    }

                    if (MessageConventionExtensions.IsEventType(messageType))
                    {
                        router.RegisterEventRoute(messageType, address);
                        return;
                    }

                    router.RegisterMessageRoute(messageType, address);
                });
            }
        }
コード例 #7
0
ファイル: UnicastBus.cs プロジェクト: xqfgbc/NServiceBus
        void RegisterMessageOwnersAndBusAddress(FeatureConfigurationContext context, IEnumerable<Type> knownMessages)
        {
            var unicastConfig = context.Settings.GetConfigSection<UnicastBusConfig>();
            var router = new StaticMessageRouter(knownMessages);
            var key = typeof(AutoSubscriptionStrategy).FullName + ".SubscribePlainMessages";

            if (context.Settings.HasSetting(key))
            {
                router.SubscribeToPlainMessages = context.Settings.Get<bool>(key);
            }

            context.Container.RegisterSingleton(router);

            if (unicastConfig == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo))
            {
                var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo);
                context.Container.ConfigureProperty<ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress);
            }

            if (unicastConfig.TimeToBeReceivedOnForwardedMessages != TimeSpan.Zero)
            {
                context.Container.ConfigureProperty<ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages);
            }

            var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast<MessageEndpointMapping>()
                .OrderByDescending(m => m)
                .ToList();

            foreach (var mapping in messageEndpointMappings)
            {
                mapping.Configure((messageType, address) =>
                {
                    var conventions = context.Settings.Get<Conventions>();
                    if (!(conventions.IsMessageType(messageType) || conventions.IsEventType(messageType) || conventions.IsCommandType(messageType)))
                    {
                        return;
                    }

                    if (conventions.IsEventType(messageType))
                    {
                        router.RegisterEventRoute(messageType, address);
                        return;
                    }

                    router.RegisterMessageRoute(messageType, address);
                });
            }
        }
コード例 #8
0
        public void When_registered_registering_multiple_addresses_for_same_type_same_number_of_addresses_are_returned()
        {
            var baseType = typeof(BaseMessage);
            var router = new StaticMessageRouter(Enumerable.Empty<Type>());
            var addressA = new Address("BaseMessage", "A");
            router.RegisterEventRoute(baseType, addressA);
            var addressB = new Address("BaseMessage", "b");
            router.RegisterEventRoute(baseType, addressB);

            Assert.AreEqual(2, router.GetDestinationFor(baseType).Count);
        }