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();
        }
        public void Start()
        {
            var endpointConfiguration = new EndpointConfiguration("DynamicHostController");

            endpointConfiguration.AzureConfigurationSource();

            endpointConfiguration.UsePersistence <InMemoryPersistence>();

            endpointConfiguration.SendOnly();
            endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            loader = new DynamicEndpointLoader(settings.StorageAccount, settings.Container);

            provisioner = new DynamicEndpointProvisioner
            {
                LocalResource      = settings.LocalResource,
                RecycleRoleOnError = settings.RecycleRoleOnError
            };

            runner = new DynamicEndpointRunner
            {
                RecycleRoleOnError             = settings.RecycleRoleOnError,
                TimeToWaitUntilProcessIsKilled = settings.TimeToWaitUntilProcessIsKilled
            };

            var endpointsToHost = loader.LoadEndpoints();

            if (endpointsToHost == null)
            {
                return;
            }

            runningServices = new List <EndpointToHost>(endpointsToHost);

            provisioner.Provision(runningServices);

            runner.Start(runningServices);

            if (!settings.AutoUpdate)
            {
                return;
            }

            monitor = new DynamicHostMonitor
            {
                Loader   = loader,
                Interval = settings.UpdateInterval
            };
            monitor.UpdatedEndpoints += UpdatedEndpoints;
            monitor.NewEndpoints     += NewEndpoints;
            monitor.RemovedEndpoints += RemovedEndpoints;
            monitor.Monitor(runningServices);
            monitor.Start();
        }
예제 #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();
        }