コード例 #1
0
        /// <summary>
        /// Wrap the given configure object storing its builder and configurer.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            busConfig = Configurer.ConfigureComponent <TpUnicastBus>(ComponentCallModelEnum.Singleton);

            ConfigureSubscriptionAuthorization();

            RegisterMessageModules();

            var cfg = GetConfigSection <UnicastBusConfig>();

            if (cfg != null)
            {
                TypesToScan.Where(t => typeof(IMessage).IsAssignableFrom(t)).ToList()
                .ForEach(t => assembliesToEndpoints[t.Assembly.GetName().Name] = string.Empty);

                foreach (MessageEndpointMapping mapping in cfg.MessageEndpointMappings)
                {
                    assembliesToEndpoints[mapping.Messages] = mapping.Endpoint;
                }

                busConfig.ConfigureProperty(b => b.DistributorControlAddress, cfg.DistributorControlAddress);
                busConfig.ConfigureProperty(b => b.DistributorDataAddress, cfg.DistributorDataAddress);
                busConfig.ConfigureProperty(b => b.ForwardReceivedMessagesTo, cfg.ForwardReceivedMessagesTo);
                busConfig.ConfigureProperty(b => b.MessageOwners, assembliesToEndpoints);
            }
        }
コード例 #2
0
        public void Configure(Configure config)
        {
            this.Builder    = config.Builder;
            this.Configurer = config.Configurer;

            this.config = Configurer.ConfigureComponent <RabbitMqTransport>(ComponentCallModelEnum.Singleton);
            var cfg = NServiceBus.Configure.GetConfigSection <RabbitMqTransportConfig>();

            if (cfg != null)
            {
                this.config.ConfigureProperty(t => t.NumberOfWorkerThreads, cfg.NumberOfWorkerThreads);
                this.config.ConfigureProperty(t => t.MaximumNumberOfRetries, cfg.MaxRetries);
                this.config.ConfigureProperty(t => t.InputBroker, cfg.InputBroker);
                this.config.ConfigureProperty(t => t.InputExchange, cfg.InputExchange);
                this.config.ConfigureProperty(t => t.InputExchangeType, cfg.InputExchangeType);
                this.config.ConfigureProperty(t => t.InputQueue, cfg.InputQueue);
                this.config.ConfigureProperty(t => t.InputRoutingKeys, cfg.InputRoutingKeys);
                this.config.ConfigureProperty(t => t.DoNotCreateInputExchange, cfg.DoNotCreateInputExchange);
                this.config.ConfigureProperty(t => t.DoNotCreateInputQueue, cfg.DoNotCreateInputQueue);
                this.config.ConfigureProperty(t => t.ErrorBroker, cfg.ErrorBroker);
                this.config.ConfigureProperty(t => t.ErrorExchange, cfg.ErrorExchange);
                this.config.ConfigureProperty(t => t.ErrorExchangeType, cfg.ErrorExchangeType);
                this.config.ConfigureProperty(t => t.ErrorQueue, cfg.ErrorQueue);
                this.config.ConfigureProperty(t => t.ErrorRoutingKeys, cfg.ErrorRoutingKeys);
                this.config.ConfigureProperty(t => t.DoNotCreateErrorExchange, cfg.DoNotCreateErrorExchange);
                this.config.ConfigureProperty(t => t.DoNotCreateErrorQueue, cfg.DoNotCreateErrorQueue);

                this.config.ConfigureProperty(t => t.TransactionTimeout, TimeSpan.FromMinutes(cfg.TransactionTimeout));
                this.config.ConfigureProperty(t => t.SendAcknowledgement, cfg.SendAcknowledgement);
            }
        }
コード例 #3
0
        /// <summary>
        /// Scans the given types for types that are message handlers
        /// then uses the Configurer to configure them into the container as single call components,
        /// finally passing them to the bus as its MessageHandlerTypes.
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        ConfigUnicastBus ConfigureMessageHandlersIn(IEnumerable <Type> types)
        {
            var handlerRegistry = new MessageHandlerRegistry();
            var handlers        = new List <Type>();

            foreach (var t in types.Where(IsMessageHandler))
            {
                Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerUnitOfWork);
                handlerRegistry.RegisterHandler(t);
                handlers.Add(t);
            }

            Configurer.RegisterSingleton <IMessageHandlerRegistry>(handlerRegistry);

            var availableDispatcherFactories = TypesToScan
                                               .Where(
                factory =>
                !factory.IsInterface && typeof(IMessageDispatcherFactory).IsAssignableFrom(factory))
                                               .ToList();

            var dispatcherMappings = GetDispatcherFactories(handlers, availableDispatcherFactories);

            //configure the message dispatcher for each handler
            busConfig.ConfigureProperty(b => b.MessageDispatcherMappings, dispatcherMappings);
            Configurer.ConfigureProperty <InvokeHandlersBehavior>(b => b.MessageDispatcherMappings, dispatcherMappings);

            availableDispatcherFactories.ToList().ForEach(factory => Configurer.ConfigureComponent(factory, DependencyLifecycle.InstancePerUnitOfWork));

            return(this);
        }
コード例 #4
0
#pragma warning disable 0618
        void RegisterMessageModules()
        {
            TypesToScan
            .Where(t => typeof(IMessageModule).IsAssignableFrom(t) && !t.IsInterface)
            .ToList()
            .ForEach(type => Configurer.ConfigureComponent(type, DependencyLifecycle.InstancePerCall));
        }
コード例 #5
0
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            _receiverConfig =
                Configurer.ConfigureComponent <ServiceBrokerMessageReceiver>(DependencyLifecycle.SingleInstance);
            _senderConfig =
                Configurer.ConfigureComponent <ServiceBrokerMessageSender>(DependencyLifecycle.SingleInstance);
            _failureConfig =
                Configurer.ConfigureComponent <ServiceBrokerFailureManager>(DependencyLifecycle.SingleInstance);

            var cfg = GetConfigSection <ServiceBrokerTransportConfig>();

            if (cfg == null)
            {
                return;
            }

            ConnectionString(cfg.ConnectionString);
            SecondsToWaitForMessage(cfg.SecondsToWaitForMessage);
            InitiatorService(cfg.InitiatorService);
            ReceiveBatchSize(cfg.ReceiveBatchSize);
            EndConversationAfterReceive(cfg.EndConversationAfterReceive);
        }
コード例 #6
0
        /// <summary>
        /// Scans the given types for types that are message handlers
        /// then uses the Configurer to configure them into the container as single call components,
        /// finally passing them to the bus as its MessageHandlerTypes.
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        protected ConfigTpUnicastBus ConfigureMessageHandlersIn(IEnumerable <Type> types)
        {
            var handlers     = new List <Type>();
            var sagaHandlers = new List <Type>();

            foreach (Type t in types)
            {
                if (IsMessageHandler(t))
                {
                    Configurer.ConfigureComponent(t, ComponentCallModelEnum.Singlecall);
                    handlers.Add(t);
                }
            }

            foreach (Type t in types)
            {
                if (IsSagaMessageHandler(t))
                {
                    sagaHandlers.Add(t);
                }
            }

            busConfig.ConfigureProperty(b => b.MessageHandlerTypes, handlers);
            busConfig.ConfigureProperty(b => b.SagaMessageHandlerTypes, sagaHandlers);

            return(this);
        }
コード例 #7
0
#pragma warning restore 0618

        void ConfigureSubscriptionAuthorization()
        {
            var authType = TypesToScan.FirstOrDefault(t => typeof(IAuthorizeSubscriptions).IsAssignableFrom(t) && !t.IsInterface);

            if (authType != null)
            {
                Configurer.ConfigureComponent(authType, DependencyLifecycle.SingleInstance);
            }
        }
コード例 #8
0
 void ConfigureBehaviors()
 {
     Instance.ForAllTypes <IBehavior <HandlerInvocationContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall));
     Instance.ForAllTypes <IBehavior <ReceiveLogicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall));
     Instance.ForAllTypes <IBehavior <ReceivePhysicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall));
     Instance.ForAllTypes <IBehavior <SendLogicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall));
     Instance.ForAllTypes <IBehavior <SendLogicalMessagesContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall));
     Instance.ForAllTypes <IBehavior <SendPhysicalMessageContext> >(t => Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall));
 }
コード例 #9
0
        private void ConfigureSubscriptionAuthorization()
        {
            Type authType =
                TypesToScan.Where(t => typeof(IAuthorizeSubscriptions).IsAssignableFrom(t) && !t.IsInterface).
                FirstOrDefault();

            if (authType != null)
            {
                Configurer.ConfigureComponent(authType, ComponentCallModelEnum.Singleton);
            }
        }
コード例 #10
0
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            this.config = Configurer.ConfigureComponent <LocalRabbitMqSubscriptionStorage>(ComponentCallModelEnum.Singleton);
            var cfg = NServiceBus.Configure.GetConfigSection <LocalRabbitMqSubscriptionStorageConfig>();

            if (cfg != null)
            {
                //configure
            }
        }
コード例 #11
0
        /// <summary>
        /// Wrap the given configure object storing its builder and configurer.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;
            busConfig  = Configurer.ConfigureComponent <UnicastBus>(DependencyLifecycle.SingleInstance)
                         .ConfigureProperty(p => p.MasterNodeAddress, config.GetMasterNodeAddress());

            ConfigureSubscriptionAuthorization();
            RegisterMessageModules();

            Configurer.ConfigureComponent <PipelineExecutor>(DependencyLifecycle.SingleInstance);
            Configurer.ConfigureComponent <PipelineBuilder>(DependencyLifecycle.SingleInstance);
            ConfigureBehaviors();
        }
コード例 #12
0
        /// <summary>
        /// Wrap the given configure object storing its builder and configurer.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;
            busConfig  = Configurer.ConfigureComponent <UnicastBus>(DependencyLifecycle.SingleInstance);

            ConfigureSubscriptionAuthorization();

            RegisterMessageModules();

            RegisterLocalMessages();

            RegisterMessageOwnersAndBusAddress();
        }
コード例 #13
0
        /// <summary>
        /// Scans the given types for types that are message handlers
        /// then uses the Configurer to configure them into the container as single call components,
        /// finally passing them to the bus as its MessageHandlerTypes.
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        protected ConfigUnicastBus ConfigureMessageHandlersIn(IEnumerable <Type> types)
        {
            var handlers = new List <Type>();

            foreach (Type t in types.Where(IsMessageHandler))
            {
                Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerCall);
                handlers.Add(t);
            }

            busConfig.ConfigureProperty(b => b.MessageHandlerTypes, handlers);

            return(this);
        }
コード例 #14
0
        /// <summary>
        /// Wrap the given configure object storing its builder and configurer.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;
            busConfig  = Configurer.ConfigureComponent <UnicastBus>(DependencyLifecycle.SingleInstance)
                         .ConfigureProperty(p => p.MasterNodeAddress, config.GetMasterNodeAddress())
                         .ConfigureProperty(p => p.TimeoutManagerAddress, config.GetTimeoutManagerAddress());

            ConfigureSubscriptionAuthorization();

            RegisterMessageModules();

            RegisterLocalMessages();

            RegisterMessageOwnersAndBusAddress();
        }
コード例 #15
0
 void ConfigureBehaviors()
 {
     Configurer.ConfigureComponent <ApplyIncomingMessageMutatorsBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <ApplyIncomingTransportMessageMutatorsBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <AuditBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <CallbackInvocationBehavior>(DependencyLifecycle.InstancePerCall);
     extractLogicalMessagesConfig = Configurer.ConfigureComponent <ExtractLogicalMessagesBehavior>(DependencyLifecycle.InstancePerCall);
     forwardConfig = Configurer.ConfigureComponent <ForwardBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <ImpersonateSenderBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <InvokeHandlersBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <LoadHandlersBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <MessageHandlingLoggingBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <UnitOfWorkBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <RaiseMessageReceivedBehavior>(DependencyLifecycle.InstancePerCall);
     Configurer.ConfigureComponent <SagaPersistenceBehavior>(DependencyLifecycle.InstancePerCall);
 }
コード例 #16
0
        /// <summary>
        /// Wraps the given configuration object but stores the same
        /// builder and configurer properties.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            transportConfig = Configurer.ConfigureComponent <TTransport>(ComponentCallModelEnum.Singleton);
            transportConfig.ConfigureProperty(x => x.PluginQueueFactory, new PluginQueueFactory());

            var cfg = GetConfigSection <MsmqTransportConfig>();

            if (cfg != null)
            {
                transportConfig.ConfigureProperty(t => t.InputQueue, cfg.InputQueue);
                transportConfig.ConfigureProperty(t => t.NumberOfWorkerThreads, cfg.NumberOfWorkerThreads);
                transportConfig.ConfigureProperty(t => t.ErrorQueue, cfg.ErrorQueue);
                transportConfig.ConfigureProperty(t => t.MaxRetries, cfg.MaxRetries);
            }
        }
コード例 #17
0
        /// <summary>
        /// Wraps the given configuration object but stores the same
        /// builder and configurer properties.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            var cfg = GetConfigSection <MsmqSubscriptionStorageConfig>();

            if (cfg == null)
            {
                Logger.Warn("Could not find configuration section for Msmq Subscription Storage.");
            }

            string q = (cfg != null ? cfg.Queue : "NServiceBus_Subscriptions");

            var storageConfig = Configurer.ConfigureComponent <MsmqSubscriptionStorage>(DependencyLifecycle.SingleInstance);

            storageConfig.ConfigureProperty(s => s.Queue, q);
        }
コード例 #18
0
        /// <summary>
        /// Wraps the given configuration object but stores the same
        /// builder and configurer properties.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            transportConfig = Configurer.ConfigureComponent <ServiceBrokerTransport>(ComponentCallModelEnum.Singleton);

            var cfg = GetConfigSection <ServiceBrokerTransportConfig>();

            if (cfg != null)
            {
                transportConfig.ConfigureProperty(t => t.InputQueue, cfg.InputQueue);
                transportConfig.ConfigureProperty(t => t.NumberOfWorkerThreads, cfg.NumberOfWorkerThreads);
                transportConfig.ConfigureProperty(t => t.ErrorService, cfg.ErrorService);
                transportConfig.ConfigureProperty(t => t.MaxRetries, cfg.MaxRetries);
                ConnectionString(cfg.ConnectionString);
                ReturnService(cfg.ReturnService);
            }
        }
コード例 #19
0
        /// <summary>
        /// Wrap the given configure object storing its builder and configurer.
        /// </summary>
        /// <param name="config"></param>
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;
            busConfig  = Configurer.ConfigureComponent <UnicastBus>(DependencyLifecycle.SingleInstance)
                         .ConfigureProperty(p => p.MasterNodeAddress, config.GetMasterNodeAddress());

            var knownMessages = TypesToScan
                                .Where(MessageConventionExtensions.IsMessageType)
                                .ToList();

            ConfigureSubscriptionAuthorization();

            RegisterMessageModules();

            RegisterMessageOwnersAndBusAddress(knownMessages);

            ConfigureMessageRegistry(knownMessages);
        }
コード例 #20
0
 private void RegisterMessageModules()
 {
     TypesToScan.Where(t => typeof(IMessageModule).IsAssignableFrom(t) && !t.IsInterface).ToList()
     .ForEach(type => Configurer.ConfigureComponent(type, ComponentCallModelEnum.Singleton));
 }
コード例 #21
0
        public void Start()
        {
            DynamicHostControllerConfig configSection = null;

            var o = new BusConfiguration();

            o.AssembliesToScan(GetType().Assembly);
            o.AzureConfigurationSource();
            o.RegisterComponents(Configurer =>
            {
                Configurer.ConfigureComponent <DynamicEndpointLoader>(DependencyLifecycle.SingleInstance);
                Configurer.ConfigureComponent <DynamicEndpointProvisioner>(DependencyLifecycle.SingleInstance);
                Configurer.ConfigureComponent <DynamicEndpointRunner>(DependencyLifecycle.SingleInstance);
                Configurer.ConfigureComponent <DynamicHostMonitor>(DependencyLifecycle.SingleInstance);

                configSection = o.GetSettings().GetConfigSection <DynamicHostControllerConfig>() ?? new DynamicHostControllerConfig();

                Configurer.ConfigureProperty <DynamicEndpointLoader>(t => t.ConnectionString, configSection.ConnectionString);
                Configurer.ConfigureProperty <DynamicEndpointLoader>(t => t.Container, configSection.Container);
                Configurer.ConfigureProperty <DynamicEndpointProvisioner>(t => t.LocalResource, configSection.LocalResource);
                Configurer.ConfigureProperty <DynamicEndpointProvisioner>(t => t.RecycleRoleOnError, configSection.RecycleRoleOnError);
                Configurer.ConfigureProperty <DynamicEndpointRunner>(t => t.RecycleRoleOnError, configSection.RecycleRoleOnError);
                Configurer.ConfigureProperty <DynamicEndpointRunner>(t => t.TimeToWaitUntilProcessIsKilled, configSection.TimeToWaitUntilProcessIsKilled);
                Configurer.ConfigureProperty <DynamicHostMonitor>(t => t.Interval, configSection.UpdateInterval);
            });

            o.UsePersistence <AzureStoragePersistence>();
            o.DiscardFailedMessagesInsteadOfSendingToErrorQueue();

            profileManager.ActivateProfileHandlers(o);
            specifier.Customize(o);

            var bus = (UnicastBus)Bus.CreateSendOnly(o);

            loader      = bus.Builder.Build <DynamicEndpointLoader>();
            provisioner = bus.Builder.Build <DynamicEndpointProvisioner>();
            runner      = bus.Builder.Build <DynamicEndpointRunner>();

            var endpointsToHost = loader.LoadEndpoints();

            if (endpointsToHost == null)
            {
                return;
            }

            runningServices = new List <EndpointToHost>(endpointsToHost);

            provisioner.Provision(runningServices);

            runner.Start(runningServices);

            if (!configSection.AutoUpdate)
            {
                return;
            }

            monitor = bus.Builder.Build <DynamicHostMonitor>();
            monitor.UpdatedEndpoints += UpdatedEndpoints;
            monitor.NewEndpoints     += NewEndpoints;
            monitor.RemovedEndpoints += RemovedEndpoints;
            monitor.Monitor(runningServices);
            monitor.Start();
        }