public static HostingComponent Initialize(Configuration configuration, ContainerComponent containerComponent, PipelineSettings pipelineSettings) { var hostingComponent = new HostingComponent(configuration); containerComponent.ContainerConfiguration.ConfigureComponent(() => hostingComponent.HostInformation, DependencyLifecycle.SingleInstance); pipelineSettings.Register("AuditHostInformation", new AuditHostInformationBehavior(hostingComponent.HostInformation, configuration.EndpointName), "Adds audit host information"); pipelineSettings.Register("AddHostInfoHeaders", new AddHostInfoHeadersBehavior(hostingComponent.HostInformation, configuration.EndpointName), "Adds host info headers to outgoing headers"); hostingComponent.AddStartupDiagnosticsSection("Hosting", new { hostingComponent.HostInformation.HostId, HostDisplayName = hostingComponent.HostInformation.DisplayName, RuntimeEnvironment.MachineName, OSPlatform = Environment.OSVersion.Platform, OSVersion = Environment.OSVersion.VersionString, GCSettings.IsServerGC, GCLatencyMode = GCSettings.LatencyMode, Environment.ProcessorCount, Environment.Is64BitProcess, CLRVersion = Environment.Version, Environment.WorkingSet, Environment.SystemPageSize, HostName = Dns.GetHostName(), Environment.UserName, PathToExe = PathUtilities.SanitizedPath(Environment.CommandLine) }); return(hostingComponent); }
public static StartableEndpointWithExternallyManagedContainer CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IConfigureComponents externalContainer) { var settings = endpointConfiguration.Settings; var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); FinalizeConfiguration(endpointConfiguration, assemblyScanningComponent.AvailableTypes); var hostingSettings = settings.Get <HostingComponent.Settings>(); var hostingConfiguration = HostingComponent.PrepareConfiguration(hostingSettings, assemblyScanningComponent, externalContainer); if (hostingSettings.CustomObjectBuilder != null) { throw new InvalidOperationException("An internally managed container has already been configured using 'EndpointConfiguration.UseContainer'. It is not possible to use both an internally managed container and an externally managed container."); } hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "external" }); var endpointCreator = new EndpointCreator(settings, hostingConfiguration); endpointCreator.Initialize(); var startableEndpoint = new StartableEndpointWithExternallyManagedContainer(endpointCreator, hostingConfiguration); //for backwards compatibility we need to make the IBuilder available in the container externalContainer.ConfigureComponent(_ => startableEndpoint.Builder.Value, DependencyLifecycle.SingleInstance); return(startableEndpoint); }
public void Initialize(ReceiveConfiguration receiveConfiguration, HostingComponent hostingComponent) { if (settings.GetOrDefault <bool>("Endpoint.SendOnly")) { //Message recoverability is only relevant for endpoints receiving messages. return; } hostInformation = hostingComponent.HostInformation; transactionsOn = receiveConfiguration.TransactionMode != TransportTransactionMode.None; var errorQueue = settings.ErrorQueueAddress(); settings.Get <QueueBindings>().BindSending(errorQueue); var delayedRetryConfig = GetDelayedRetryConfig(); var immediateRetryConfig = GetImmediateRetryConfig(); var failedConfig = new FailedConfig(errorQueue, settings.UnrecoverableExceptions()); recoverabilityConfig = new RecoverabilityConfig(immediateRetryConfig, delayedRetryConfig, failedConfig); hostingComponent.AddStartupDiagnosticsSection("Recoverability", new { ImmediateRetries = recoverabilityConfig.Immediate.MaxNumberOfRetries, DelayedRetries = recoverabilityConfig.Delayed.MaxNumberOfRetries, DelayedRetriesTimeIncrease = recoverabilityConfig.Delayed.TimeIncrease.ToString("g"), recoverabilityConfig.Failed.ErrorQueue, UnrecoverableExceptions = recoverabilityConfig.Failed.UnrecoverableExceptionTypes.Select(t => t.FullName).ToArray() }); WireUpLegacyNotifications(); }
public static ExternallyManagedContainerHost CreateWithExternallyManagedContainer(EndpointConfiguration endpointConfiguration, IServiceCollection serviceCollection) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var hostingSettings = settings.Get <HostingComponent.Settings>(); var hostingConfiguration = HostingComponent.PrepareConfiguration(hostingSettings, assemblyScanningComponent, serviceCollection); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "external" }); var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var externallyManagedContainerHost = new ExternallyManagedContainerHost(endpointCreator, hostingConfiguration); return(externallyManagedContainerHost); }
public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration, CancellationToken cancellationToken = default) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var serviceCollection = new ServiceCollection(); var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, serviceCollection); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "internal" }); var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration, serviceCollection, true); var serviceProvider = serviceCollection.BuildServiceProvider(); var startableEndpoint = endpointCreator.CreateStartableEndpoint(serviceProvider, hostingComponent); hostingComponent.RegisterBuilder(serviceProvider); await hostingComponent.RunInstallers(cancellationToken).ConfigureAwait(false); return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent)); }
public RunningEndpointInstance(SettingsHolder settings, HostingComponent hostingComponent, ReceiveComponent receiveComponent, FeatureComponent featureComponent, IMessageSession messageSession, TransportInfrastructure transportInfrastructure) { this.settings = settings; this.hostingComponent = hostingComponent; this.receiveComponent = receiveComponent; this.featureComponent = featureComponent; this.messageSession = messageSession; this.transportInfrastructure = transportInfrastructure; }
public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var hostingSetting = settings.Get <HostingComponent.Settings>(); var useDefaultBuilder = hostingSetting.CustomObjectBuilder == null; var container = useDefaultBuilder ? new LightInjectObjectBuilder() : hostingSetting.CustomObjectBuilder; var commonObjectBuilder = new CommonObjectBuilder(container); IConfigureComponents internalContainer = commonObjectBuilder; IBuilder internalBuilder = commonObjectBuilder; //for backwards compatibility we need to make the IBuilder available in the container internalContainer.ConfigureComponent(_ => internalBuilder, DependencyLifecycle.SingleInstance); var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, internalContainer); if (useDefaultBuilder) { hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "internal" }); } else { var containerType = internalContainer.GetType(); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = containerType.FullName, Version = FileVersionRetriever.GetFileVersion(containerType) }); } var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration); var startableEndpoint = endpointCreator.CreateStartableEndpoint(internalBuilder, hostingComponent); hostingComponent.RegisterBuilder(internalBuilder, true); await hostingComponent.RunInstallers().ConfigureAwait(false); return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent)); }
public IStartableEndpoint CreateStartableEndpoint(IBuilder builder, HostingComponent hostingComponent) { return(new StartableEndpoint(settings, featureComponent, receiveComponent, transportSeam.TransportInfrastructure, pipelineComponent, recoverabilityComponent, hostingComponent, sendComponent, builder)); }
public IStartableEndpoint CreateStartableEndpoint(IServiceProvider builder, HostingComponent hostingComponent) { return(new StartableEndpoint(settings, featureComponent, receiveComponent, transportSeam, pipelineComponent, recoverabilityComponent, hostingComponent, sendComponent, builder)); }
public async Task <IEndpointInstance> Start(IBuilder builder) { objectBuilder = builder; var hostingComponent = HostingComponent.Initialize(hostingConfiguration, null); var startableEndpoint = await endpointCreator.CreateStartableEndpoint(builder, hostingComponent).ConfigureAwait(false); var endpointInstance = await startableEndpoint.Start().ConfigureAwait(false); messageSession = endpointInstance; return(endpointInstance); }
public static ReceiveComponent Initialize(ReceiveConfiguration receiveConfiguration, TransportComponent transportComponent, PipelineComponent pipeline, EventAggregator eventAggregator, CriticalError criticalError, string errorQueue, HostingComponent hostingComponent) { Func <IPushMessages> messagePumpFactory = null; //we don't need the message pump factory for send-only endpoints if (receiveConfiguration != null) { messagePumpFactory = transportComponent.GetMessagePumpFactory(); } var receiveComponent = new ReceiveComponent(receiveConfiguration, messagePumpFactory, pipeline, eventAggregator, criticalError, errorQueue); receiveComponent.BindQueues(transportComponent.QueueBindings); if (receiveConfiguration != null) { hostingComponent.AddStartupDiagnosticsSection("Receiving", new { receiveConfiguration.LocalAddress, receiveConfiguration.InstanceSpecificQueue, receiveConfiguration.LogicalAddress, receiveConfiguration.PurgeOnStartup, receiveConfiguration.QueueNameBase, TransactionMode = receiveConfiguration.TransactionMode.ToString("G"), receiveConfiguration.PushRuntimeSettings.MaxConcurrency, Satellites = receiveConfiguration.SatelliteDefinitions.Select(s => new { s.Name, s.ReceiveAddress, TransactionMode = s.RequiredTransportTransactionMode.ToString("G"), s.RuntimeSettings.MaxConcurrency }).ToArray() }); } return(receiveComponent); }
public async Task <IEndpointInstance> Start(IServiceProvider externalBuilder) { objectBuilder = externalBuilder; var hostingComponent = HostingComponent.Initialize(hostingConfiguration); var startableEndpoint = endpointCreator.CreateStartableEndpoint(externalBuilder, hostingComponent); hostingComponent.RegisterBuilder(externalBuilder, false); await hostingComponent.RunInstallers().ConfigureAwait(false); var endpointInstance = await hostingComponent.Start(startableEndpoint).ConfigureAwait(false); messageSession = endpointInstance; return(endpointInstance); }
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; }
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; }
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; }
public ExternallyManagedContainerHost(EndpointCreator endpointCreator, HostingComponent hostingComponent) { this.endpointCreator = endpointCreator; this.hostingComponent = hostingComponent; MessageSession = new Lazy <IMessageSession>(() => { if (messageSession == null) { throw new InvalidOperationException("The message session can only be used after the endpoint is started."); } return(messageSession); }); Builder = new Lazy <IServiceProvider>(() => { if (objectBuilder == null) { throw new InvalidOperationException("The builder can only be used after the endpoint is started."); } return(objectBuilder); }); }
public static async Task <IStartableEndpoint> CreateWithInternallyManagedContainer(EndpointConfiguration endpointConfiguration) { var settings = endpointConfiguration.Settings; CheckIfSettingsWhereUsedToCreateAnotherEndpoint(settings); var assemblyScanningComponent = AssemblyScanningComponent.Initialize(settings.Get <AssemblyScanningComponent.Configuration>(), settings); endpointConfiguration.FinalizeConfiguration(assemblyScanningComponent.AvailableTypes); var serviceCollection = new MicrosoftExtensionsDependencyInjection.ServiceCollection(); var hostingConfiguration = HostingComponent.PrepareConfiguration(settings.Get <HostingComponent.Settings>(), assemblyScanningComponent, serviceCollection); hostingConfiguration.AddStartupDiagnosticsSection("Container", new { Type = "internal" }); var endpointCreator = EndpointCreator.Create(settings, hostingConfiguration); var hostingComponent = HostingComponent.Initialize(hostingConfiguration); var containerOptions = new ContainerOptions { EnableVariance = false }.WithMicrosoftSettings(); var serviceProvider = serviceCollection.CreateLightInjectServiceProvider(containerOptions); var startableEndpoint = endpointCreator.CreateStartableEndpoint(serviceProvider, hostingComponent); hostingComponent.RegisterBuilder(serviceProvider, true); await hostingComponent.RunInstallers().ConfigureAwait(false); return(new InternallyManagedContainerHost(startableEndpoint, hostingComponent)); }
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); transportComponent = TransportComponent.Initialize(settings.Get <TransportComponent.Configuration>(), settings); var receiveConfiguration = BuildReceiveConfiguration(transportComponent); var routingComponent = new RoutingComponent(settings); var pipelineSettings = settings.Get <PipelineSettings>(); routingComponent.Initialize(transportComponent, pipelineSettings, receiveConfiguration); var messageMapper = new MessageMapper(); settings.Set <IMessageMapper>(messageMapper); recoverabilityComponent = new RecoverabilityComponent(settings); var featureConfigurationContext = new FeatureConfigurationContext(settings, containerComponent.ContainerConfiguration, 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(); hostingComponent = HostingComponent.Initialize(settings.Get <HostingComponent.Configuration>(), containerComponent, pipelineSettings); recoverabilityComponent.Initialize(receiveConfiguration, hostingComponent); pipelineComponent = PipelineComponent.Initialize(pipelineSettings, containerComponent); pipelineComponent.AddRootContextItem <IMessageMapper>(messageMapper); containerComponent.ContainerConfiguration.ConfigureComponent(b => settings.Get <Notifications>(), DependencyLifecycle.SingleInstance); var eventAggregator = new EventAggregator(settings.Get <NotificationSubscriptions>()); pipelineComponent.AddRootContextItem <IEventAggregator>(eventAggregator); receiveComponent = ReceiveComponent.Initialize(receiveConfiguration, transportComponent, pipelineComponent, eventAggregator, criticalError, settings.ErrorQueueAddress(), hostingComponent); installationComponent = InstallationComponent.Initialize(settings.Get <InstallationComponent.Configuration>(), concreteTypes, containerComponent, transportComponent); settings.AddStartupDiagnosticsSection("Endpoint", new { Name = settings.EndpointName(), SendOnly = settings.Get <bool>("Endpoint.SendOnly"), NServiceBusVersion = GitVersionInformation.MajorMinorPatch } ); }
public async Task <IStartableEndpoint> CreateStartableEndpoint(IBuilder builder, HostingComponent hostingComponent) { // This is the only component that is started before the user actually calls .Start(). This is due to an old "feature" that allowed users to // run installers by "just creating the endpoint". See https://docs.particular.net/nservicebus/operations/installers#running-installers for more details. await installationComponent.Start(builder, transportComponent).ConfigureAwait(false); return(new StartableEndpoint(settings, featureComponent, transportComponent, receiveComponent, pipelineComponent, recoverabilityComponent, hostingComponent, sendComponent, builder)); }
public InternallyManagedContainerHost(IStartableEndpoint startableEndpoint, HostingComponent hostingComponent) { this.startableEndpoint = startableEndpoint; this.hostingComponent = hostingComponent; }