Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public ConfigUnicastBus SkipDeserialization()
        {
            busConfig.ConfigureProperty(b => b.SkipDeserialization, true);
            Configurer.ConfigureProperty <ExtractLogicalMessagesBehavior>(b => b.SkipDeserialization, true);

            return(this);
        }
Ejemplo n.º 3
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();
        }