Пример #1
0
        public async Task PrepareToStart(ContainerComponent containerComponent, RecoverabilityComponent recoverabilityComponent)
        {
            if (IsSendOnly)
            {
                return;
            }

            mainPipelineExecutor = new MainPipelineExecutor(containerComponent.Builder, pipeline);

            if (configuration.PurgeOnStartup)
            {
                Logger.Warn("All queues owned by the endpoint will be purged on startup.");
            }

            AddReceivers(containerComponent.Builder, recoverabilityComponent.GetRecoverabilityExecutorFactory(containerComponent.Builder));

            foreach (var receiver in receivers)
            {
                try
                {
                    await receiver.Init().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Logger.Fatal($"Receiver {receiver.Id} failed to initialize.", ex);
                    throw;
                }
            }
        }
        public async Task PrepareToStart(IBuilder builder,
                                         RecoverabilityComponent recoverabilityComponent,
                                         MessageOperations messageOperations,
                                         PipelineComponent pipelineComponent,
                                         IPipelineCache pipelineCache)
        {
            if (configuration.IsSendOnlyEndpoint)
            {
                return;
            }

            var receivePipeline = pipelineComponent.CreatePipeline <ITransportReceiveContext>(builder);

            mainPipelineExecutor = new MainPipelineExecutor(builder, pipelineCache, messageOperations, configuration.PipelineCompletedSubscribers, receivePipeline);

            if (configuration.PurgeOnStartup)
            {
                Logger.Warn("All queues owned by the endpoint will be purged on startup.");
            }

            AddReceivers(builder, recoverabilityComponent.GetRecoverabilityExecutorFactory(builder), transportReceiveInfrastructure.MessagePumpFactory);

            foreach (var receiver in receivers)
            {
                try
                {
                    await receiver.Init().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Logger.Fatal($"Receiver {receiver.Id} failed to initialize.", ex);
                    throw;
                }
            }
        }
Пример #3
0
        public async Task Initialize(IServiceProvider builder,
                                     RecoverabilityComponent recoverabilityComponent,
                                     MessageOperations messageOperations,
                                     PipelineComponent pipelineComponent,
                                     IPipelineCache pipelineCache,
                                     TransportInfrastructure transportInfrastructure,
                                     CancellationToken cancellationToken = default)
        {
            if (configuration.IsSendOnlyEndpoint)
            {
                return;
            }

            var mainPump = transportInfrastructure.Receivers[MainReceiverId];

            var receivePipeline               = pipelineComponent.CreatePipeline <ITransportReceiveContext>(builder);
            var mainPipelineExecutor          = new MainPipelineExecutor(builder, pipelineCache, messageOperations, configuration.PipelineCompletedSubscribers, receivePipeline);
            var recoverabilityExecutorFactory = recoverabilityComponent.GetRecoverabilityExecutorFactory(builder);
            var recoverability = recoverabilityExecutorFactory
                                 .CreateDefault(configuration.LocalAddress);

            await mainPump.Initialize(configuration.PushRuntimeSettings, mainPipelineExecutor.Invoke,
                                      recoverability.Invoke, cancellationToken).ConfigureAwait(false);

            receivers.Add(mainPump);

            if (transportInfrastructure.Receivers.TryGetValue(InstanceSpecificReceiverId, out var instanceSpecificPump))
            {
                var instanceSpecificRecoverabilityExecutor = recoverabilityExecutorFactory.CreateDefault(configuration.InstanceSpecificQueue);

                await instanceSpecificPump.Initialize(configuration.PushRuntimeSettings, mainPipelineExecutor.Invoke,
                                                      instanceSpecificRecoverabilityExecutor.Invoke, cancellationToken).ConfigureAwait(false);

                receivers.Add(instanceSpecificPump);
            }

            foreach (var satellite in configuration.SatelliteDefinitions)
            {
                try
                {
                    var satellitePump = transportInfrastructure.Receivers[satellite.Name];

                    var satellitePipeline = new SatellitePipelineExecutor(builder, satellite);
                    var satelliteRecoverabilityExecutor = recoverabilityExecutorFactory.Create(satellite.RecoverabilityPolicy, satellite.ReceiveAddress);

                    await satellitePump.Initialize(satellite.RuntimeSettings, satellitePipeline.Invoke,
                                                   satelliteRecoverabilityExecutor.Invoke, cancellationToken).ConfigureAwait(false);

                    receivers.Add(satellitePump);
                }
                catch (Exception ex) when(!ex.IsCausedBy(cancellationToken))
                {
                    Logger.Fatal("Satellite failed to start.", ex);
                    throw;
                }
            }
        }
Пример #4
0
 public StartableEndpoint(SettingsHolder settings,
                          FeatureComponent featureComponent,
                          ReceiveComponent receiveComponent,
                          TransportInfrastructure transportInfrastructure,
                          PipelineComponent pipelineComponent,
                          RecoverabilityComponent recoverabilityComponent,
                          HostingComponent hostingComponent,
                          SendComponent sendComponent,
                          IBuilder builder)
 {
     this.settings                = settings;
     this.featureComponent        = featureComponent;
     this.receiveComponent        = receiveComponent;
     this.transportInfrastructure = transportInfrastructure;
     this.pipelineComponent       = pipelineComponent;
     this.recoverabilityComponent = recoverabilityComponent;
     this.hostingComponent        = hostingComponent;
     this.sendComponent           = sendComponent;
     this.builder = builder;
 }
Пример #5
0
 public StartableEndpoint(SettingsHolder settings,
                          ContainerComponent containerComponent,
                          FeatureComponent featureComponent,
                          TransportComponent transportComponent,
                          ReceiveComponent receiveComponent,
                          CriticalError criticalError,
                          PipelineComponent pipelineComponent,
                          RecoverabilityComponent recoverabilityComponent,
                          HostingComponent hostingComponent)
 {
     this.criticalError           = criticalError;
     this.settings                = settings;
     this.containerComponent      = containerComponent;
     this.featureComponent        = featureComponent;
     this.transportComponent      = transportComponent;
     this.receiveComponent        = receiveComponent;
     this.pipelineComponent       = pipelineComponent;
     this.recoverabilityComponent = recoverabilityComponent;
     this.hostingComponent        = hostingComponent;
 }
Пример #6
0
 public StartableEndpoint(SettingsHolder settings,
                          FeatureComponent featureComponent,
                          ReceiveComponent receiveComponent,
                          TransportSeam transportSeam,
                          PipelineComponent pipelineComponent,
                          RecoverabilityComponent recoverabilityComponent,
                          HostingComponent hostingComponent,
                          SendComponent sendComponent,
                          IServiceProvider builder)
 {
     this.settings                = settings;
     this.featureComponent        = featureComponent;
     this.receiveComponent        = receiveComponent;
     this.transportSeam           = transportSeam;
     this.pipelineComponent       = pipelineComponent;
     this.recoverabilityComponent = recoverabilityComponent;
     this.hostingComponent        = hostingComponent;
     this.sendComponent           = sendComponent;
     this.builder = builder;
 }
Пример #7
0
        void Initialize()
        {
            containerComponent.ContainerConfiguration.RegisterSingleton <ReadOnlySettings>(settings);

            RegisterCriticalErrorHandler();

            var concreteTypes = settings.GetAvailableTypes()
                                .Where(IsConcrete)
                                .ToList();

            featureComponent = new FeatureComponent(settings);

            // This needs to happen here to make sure that features enabled state is present in settings so both
            // IWantToRunBeforeConfigurationIsFinalized implementations and transports can check access it
            featureComponent.RegisterFeatureEnabledStatusInSettings(concreteTypes);

            ConfigRunBeforeIsFinalized(concreteTypes);

            transportInfrastructure = InitializeTransportComponent();

            var receiveConfiguration = BuildReceiveConfiguration(transportInfrastructure);

            var routingComponent = new RoutingComponent(settings);

            routingComponent.Initialize(transportInfrastructure, pipelineComponent, receiveConfiguration);

            var messageMapper = new MessageMapper();

            settings.Set <IMessageMapper>(messageMapper);

            pipelineComponent.AddRootContextItem <IMessageMapper>(messageMapper);

            recoverabilityComponent = new RecoverabilityComponent(settings);

            var featureConfigurationContext = new FeatureConfigurationContext(settings, containerComponent.ContainerConfiguration, pipelineComponent.PipelineSettings, routingComponent, receiveConfiguration);

            featureComponent.Initalize(containerComponent, featureConfigurationContext);
            //The settings can only be locked after initializing the feature component since it uses the settings to store & share feature state.
            settings.PreventChanges();

            recoverabilityComponent.Initialize(receiveConfiguration);

            pipelineComponent.Initialize(containerComponent);
            containerComponent.ContainerConfiguration.ConfigureComponent(b => settings.Get <Notifications>(), DependencyLifecycle.SingleInstance);

            var eventAggregator = new EventAggregator(settings.Get <NotificationSubscriptions>());

            pipelineComponent.AddRootContextItem <IEventAggregator>(eventAggregator);

            var shouldRunInstallers = settings.GetOrDefault <bool>("Installers.Enable");

            if (shouldRunInstallers)
            {
                RegisterInstallers(concreteTypes);
            }

            settings.AddStartupDiagnosticsSection("Endpoint",
                                                  new
            {
                Name               = settings.EndpointName(),
                SendOnly           = settings.Get <bool>("Endpoint.SendOnly"),
                NServiceBusVersion = GitVersionInformation.MajorMinorPatch
            }
                                                  );

            queueBindings    = settings.Get <QueueBindings>();
            receiveComponent = CreateReceiveComponent(receiveConfiguration, transportInfrastructure, pipelineComponent, queueBindings, eventAggregator);
        }
Пример #8
0
 public StartableEndpoint(SettingsHolder settings, ContainerComponent containerComponent, FeatureComponent featureComponent, TransportInfrastructure transportInfrastructure, ReceiveComponent receiveComponent, CriticalError criticalError, IMessageSession messageSession, RecoverabilityComponent recoverabilityComponent)
 {
     this.criticalError           = criticalError;
     this.settings                = settings;
     this.containerComponent      = containerComponent;
     this.featureComponent        = featureComponent;
     this.transportInfrastructure = transportInfrastructure;
     this.receiveComponent        = receiveComponent;
     this.messageSession          = messageSession;
     this.recoverabilityComponent = recoverabilityComponent;
 }
Пример #9
0
        void Initialize()
        {
            var pipelineSettings = settings.Get <PipelineSettings>();

            hostingConfiguration.Container.RegisterSingleton <ReadOnlySettings>(settings);

            featureComponent = new FeatureComponent(settings);

            // This needs to happen here to make sure that features enabled state is present in settings so both
            // IWantToRunBeforeConfigurationIsFinalized implementations and transports can check access it
            featureComponent.RegisterFeatureEnabledStatusInSettings(hostingConfiguration);

            ConfigRunBeforeIsFinalized(hostingConfiguration);

            var transportConfiguration = TransportComponent.PrepareConfiguration(settings.Get <TransportComponent.Settings>());

            var receiveConfiguration = BuildReceiveConfiguration(transportConfiguration);

            var routingComponent = RoutingComponent.Initialize(
                settings.Get <RoutingComponent.Configuration>(),
                transportConfiguration,
                receiveConfiguration,
                settings.Get <Conventions>(),
                pipelineSettings);

            var messageMapper = new MessageMapper();

            settings.Set <IMessageMapper>(messageMapper);

            recoverabilityComponent = new RecoverabilityComponent(settings);

            var featureConfigurationContext = new FeatureConfigurationContext(settings, hostingConfiguration.Container, pipelineSettings, routingComponent, receiveConfiguration);

            featureComponent.Initalize(featureConfigurationContext);

            hostingConfiguration.CreateHostInformationForV7BackwardsCompatibility();

            recoverabilityComponent.Initialize(receiveConfiguration, hostingConfiguration);

            sendComponent = SendComponent.Initialize(pipelineSettings, hostingConfiguration, routingComponent, messageMapper);

            pipelineComponent = PipelineComponent.Initialize(pipelineSettings, hostingConfiguration);

            hostingConfiguration.Container.ConfigureComponent(b => settings.Get <Notifications>(), DependencyLifecycle.SingleInstance);

            receiveComponent = ReceiveComponent.Initialize(
                settings.Get <ReceiveComponent.Configuration>(),
                receiveConfiguration,
                transportConfiguration,
                pipelineComponent,
                settings.ErrorQueueAddress(),
                hostingConfiguration,
                pipelineSettings);

            installationComponent = InstallationComponent.Initialize(settings.Get <InstallationComponent.Configuration>(),
                                                                     hostingConfiguration);

            // The settings can only be locked after initializing the feature component since it uses the settings to store & share feature state.
            // As well as all the other components have been initialized
            settings.PreventChanges();

            transportComponent = TransportComponent.Initialize(transportConfiguration, hostingConfiguration);

            settings.AddStartupDiagnosticsSection("Endpoint",
                                                  new
            {
                Name               = settings.EndpointName(),
                SendOnly           = settings.Get <bool>("Endpoint.SendOnly"),
                NServiceBusVersion = GitVersionInformation.MajorMinorPatch
            }
                                                  );
        }
Пример #10
0
        void Configure()
        {
            ConfigureMessageTypes();

            var pipelineSettings = settings.Get <PipelineSettings>();

            hostingConfiguration.Services.AddSingleton(typeof(ReadOnlySettings), settings);

            featureComponent = new FeatureComponent(settings);

            // This needs to happen here to make sure that features enabled state is present in settings so both
            // IWantToRunBeforeConfigurationIsFinalized implementations and transports can check access it
            featureComponent.RegisterFeatureEnabledStatusInSettings(hostingConfiguration);

            transportSeam = TransportSeam.Create(settings.Get <TransportSeam.Settings>(), hostingConfiguration);

            var receiveConfiguration = ReceiveComponent.PrepareConfiguration(
                hostingConfiguration,
                settings.Get <ReceiveComponent.Settings>(),
                transportSeam);

            var routingConfiguration = RoutingComponent.Configure(settings.Get <RoutingComponent.Settings>());

            var messageMapper = new MessageMapper();

            settings.Set <IMessageMapper>(messageMapper);

            recoverabilityComponent = new RecoverabilityComponent(settings);

            var featureConfigurationContext = new FeatureConfigurationContext(settings, hostingConfiguration.Services, pipelineSettings, routingConfiguration, receiveConfiguration);

            featureComponent.Initalize(featureConfigurationContext);

            recoverabilityComponent.Initialize(receiveConfiguration, hostingConfiguration, transportSeam);

            var routingComponent = RoutingComponent.Initialize(
                routingConfiguration,
                transportSeam,
                receiveConfiguration,
                settings.Get <Conventions>(),
                pipelineSettings);

            sendComponent = SendComponent.Initialize(pipelineSettings, hostingConfiguration, routingComponent, messageMapper);

            hostingConfiguration.Services.ConfigureComponent(b => settings.Get <Notifications>(), DependencyLifecycle.SingleInstance);

            receiveComponent = ReceiveComponent.Configure(
                receiveConfiguration,
                settings.ErrorQueueAddress(),
                hostingConfiguration,
                pipelineSettings);

            pipelineComponent = PipelineComponent.Initialize(pipelineSettings, hostingConfiguration);

            // The settings can only be locked after initializing the feature component since it uses the settings to store & share feature state.
            // As well as all the other components have been initialized
            settings.PreventChanges();

            // The pipeline settings can be locked after the endpoint is configured. It prevents end users from modyfing pipeline after an endpoint has started.
            pipelineSettings.PreventChanges();

            settings.AddStartupDiagnosticsSection("Endpoint",
                                                  new
            {
                Name               = settings.EndpointName(),
                SendOnly           = settings.Get <bool>("Endpoint.SendOnly"),
                NServiceBusVersion = GitVersionInformation.MajorMinorPatch
            }
                                                  );
        }