Exemplo n.º 1
0
        static Task StartEndpoint(IConfigureThisEndpoint endpoint, CancellationToken token, EventWaitHandle sequentialStarter)
        {
            return(Task.Factory.StartNew(() =>
            {
                var config = new BusConfiguration();
                endpoint.Customize(config);

                config.ScaleOut().UseSingleBrokerQueue();
                config.UseTransport <AzureServiceBusTransport>();
                config.UsePersistence <NHibernatePersistence>();

                sequentialStarter.WaitOne();

                var bus = Bus.Create(config);
                using (bus.Start())
                {
                    sequentialStarter.Set();
                    token.WaitHandle.WaitOne();
                }
            }));
        }
Exemplo n.º 2
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();
        }