Beispiel #1
0
        public void Initialize(TransportInfrastructure transportInfrastructure, PipelineComponent pipelineComponent, ReceiveConfiguration receiveConfiguration)
        {
            var conventions             = settings.Get <Conventions>();
            var configuredUnicastRoutes = settings.GetOrDefault <ConfiguredUnicastRoutes>();

            if (settings.TryGet(out List <DistributionStrategy> distributionStrategies))
            {
                foreach (var distributionStrategy in distributionStrategies)
                {
                    DistributionPolicy.SetDistributionStrategy(distributionStrategy);
                }
            }

            configuredUnicastRoutes?.Apply(UnicastRoutingTable, conventions);

            var pipelineSettings = pipelineComponent.PipelineSettings;

            pipelineSettings.Register(b =>
            {
                var router = new UnicastSendRouter(receiveConfiguration == null, receiveConfiguration?.QueueNameBase, receiveConfiguration?.InstanceSpecificQueue, DistributionPolicy, UnicastRoutingTable, EndpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)));
                return(new UnicastSendRouterConnector(router));
            }, "Determines how the message being sent should be routed");

            pipelineSettings.Register(new UnicastReplyRouterConnector(), "Determines how replies should be routed");

            EnforceBestPractices = ShouldEnforceBestPractices(settings);
            if (EnforceBestPractices)
            {
                EnableBestPracticeEnforcement(conventions, pipelineSettings);
            }
        }
Beispiel #2
0
        public void Initialize(ReadOnlySettings settings, TransportInfrastructure transportInfrastructure, PipelineSettings pipelineSettings)
        {
            var unicastBusConfig        = settings.GetConfigSection <UnicastBusConfig>();
            var conventions             = settings.Get <Conventions>();
            var configuredUnicastRoutes = settings.GetOrDefault <ConfiguredUnicastRoutes>();
            var distributorAddress      = settings.GetOrDefault <string>("LegacyDistributor.Address");

            List <DistributionStrategy> distributionStrategies;

            if (settings.TryGet(out distributionStrategies))
            {
                foreach (var distributionStrategy in distributionStrategies)
                {
                    DistributionPolicy.SetDistributionStrategy(distributionStrategy);
                }
            }

            unicastBusConfig?.MessageEndpointMappings.Apply(Publishers, UnicastRoutingTable, transportInfrastructure.MakeCanonicalForm, conventions);
            configuredUnicastRoutes?.Apply(UnicastRoutingTable, conventions);

            pipelineSettings.Register(b =>
            {
                var router = new UnicastSendRouter(settings.GetOrDefault <string>("BaseInputQueueName"), settings.EndpointName(), settings.InstanceSpecificQueue(), distributorAddress, DistributionPolicy, UnicastRoutingTable, EndpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)));
                return(new UnicastSendRouterConnector(router));
            }, "Determines how the message being sent should be routed");

            pipelineSettings.Register(new UnicastReplyRouterConnector(), "Determines how replies should be routed");

            EnforceBestPractices = ShouldEnforceBestPractices(settings);
            if (EnforceBestPractices)
            {
                EnableBestPracticeEnforcement(conventions, pipelineSettings);
            }
        }
 public Configuration(TransportInfrastructure transportInfrastructure, QueueBindings queueBindings, bool receivingEnabled)
 {
     this.transportInfrastructure = transportInfrastructure;
     QueueBindings    = queueBindings;
     ReceivingEnabled = receivingEnabled;
     TransportType    = transportInfrastructure.GetType();
 }
Beispiel #4
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;
                }
            }
        }
Beispiel #5
0
        RoutingComponent InitializeRouting(TransportInfrastructure transportInfrastructure, ReceiveConfiguration receiveConfiguration)
        {
            // use GetOrCreate to use of instances already created during EndpointConfiguration.
            var routing = new RoutingComponent(
                settings.GetOrCreate <UnicastRoutingTable>(),
                settings.GetOrCreate <DistributionPolicy>(),
                settings.GetOrCreate <EndpointInstances>(),
                settings.GetOrCreate <Publishers>());

            routing.Initialize(settings, transportInfrastructure.ToTransportAddress, pipelineComponent.PipelineSettings, receiveConfiguration);

            return(routing);
        }
Beispiel #6
0
        ReceiveConfiguration BuildReceiveConfiguration(TransportInfrastructure transportInfrastructure)
        {
            var receiveConfiguration = ReceiveConfigurationBuilder.Build(settings, transportInfrastructure);

            if (receiveConfiguration == null)
            {
                return(null);
            }

            //note: remove once settings.LogicalAddress() , .LocalAddress() and .InstanceSpecificQueue() has been obsoleted
            settings.Set(receiveConfiguration);

            return(receiveConfiguration);
        }
        ReceiveComponent CreateReceiveComponent(ReceiveConfiguration receiveConfiguration,
                                                TransportInfrastructure transportInfrastructure,
                                                QueueBindings queueBindings,
                                                IPipelineCache pipelineCache,
                                                EventAggregator eventAggregator,
                                                IMessageMapper messageMapper)
        {
            var errorQueue = settings.ErrorQueueAddress();

            var receiveComponent = new ReceiveComponent(receiveConfiguration,
                                                        receiveConfiguration != null ? transportInfrastructure.ConfigureReceiveInfrastructure() : null, //don't create the receive infrastructure for send-only endpoints
                                                        pipelineCache,
                                                        pipelineConfiguration,
                                                        eventAggregator,
                                                        builder,
                                                        criticalError,
                                                        errorQueue,
                                                        messageMapper);

            receiveComponent.BindQueues(queueBindings);

            if (receiveConfiguration != null)
            {
                settings.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 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 static ReceiveConfiguration Build(ReadOnlySettings settings, TransportInfrastructure transportInfrastructure)
        {
            var isSendOnlyEndpoint = settings.Get <bool>("Endpoint.SendOnly");

            if (isSendOnlyEndpoint)
            {
                if (settings.HasExplicitValue(ReceiveSettingsExtensions.CustomLocalAddressKey))
                {
                    throw new Exception($"Specifying a base name for the input queue using `{nameof(ReceiveSettingsExtensions.OverrideLocalAddress)}(baseInputQueueName)` is not supported for send-only endpoints.");
                }
                return(null);
            }

            var endpointName   = settings.EndpointName();
            var discriminator  = settings.GetOrDefault <string>("EndpointInstanceDiscriminator");
            var queueNameBase  = settings.GetOrDefault <string>(ReceiveSettingsExtensions.CustomLocalAddressKey) ?? endpointName;
            var purgeOnStartup = settings.GetOrDefault <bool>("Transport.PurgeOnStartup");

            //note: This is an old hack, we are passing the endpoint name to bind but we only care about the properties
            var mainInstanceProperties = transportInfrastructure.BindToLocalEndpoint(new EndpointInstance(endpointName)).Properties;

            var logicalAddress = LogicalAddress.CreateLocalAddress(queueNameBase, mainInstanceProperties);

            var localAddress = transportInfrastructure.ToTransportAddress(logicalAddress);

            string instanceSpecificQueue = null;

            if (discriminator != null)
            {
                instanceSpecificQueue = transportInfrastructure.ToTransportAddress(logicalAddress.CreateIndividualizedAddress(discriminator));
            }

            var transactionMode = GetRequiredTransactionMode(settings);

            var pushRuntimeSettings = GetDequeueLimitations(settings);

            return(new ReceiveConfiguration(logicalAddress, queueNameBase, localAddress, instanceSpecificQueue, transactionMode, pushRuntimeSettings, purgeOnStartup));
        }
 SendComponent(IMessageMapper messageMapper, TransportInfrastructure transportInfrastructure)
 {
     this.messageMapper           = messageMapper;
     this.transportInfrastructure = transportInfrastructure;
 }
Beispiel #11
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;
 }
Beispiel #12
0
 protected TransportSeam(TransportInfrastructure transportInfrastructure, QueueBindings queueBindings)
 {
     TransportInfrastructure = transportInfrastructure;
     QueueBindings           = queueBindings;
 }
 public RunningEndpointInstance(SettingsHolder settings, HostingComponent hostingComponent, ReceiveComponent receiveComponent, FeatureComponent featureComponent, IMessageSession messageSession, TransportInfrastructure transportInfrastructure, CancellationTokenSource stoppingTokenSource)
 {
     this.settings                = settings;
     this.hostingComponent        = hostingComponent;
     this.receiveComponent        = receiveComponent;
     this.featureComponent        = featureComponent;
     this.messageSession          = messageSession;
     this.transportInfrastructure = transportInfrastructure;
     this.stoppingTokenSource     = stoppingTokenSource;
 }
 public StartableEndpoint(SettingsHolder settings, IBuilder builder, FeatureActivator featureActivator, TransportInfrastructure transportInfrastructure, ReceiveComponent receiveComponent, CriticalError criticalError, IMessageSession messageSession)
 {
     this.criticalError           = criticalError;
     this.settings                = settings;
     this.builder                 = builder;
     this.featureActivator        = featureActivator;
     this.transportInfrastructure = transportInfrastructure;
     this.receiveComponent        = receiveComponent;
     this.messageSession          = messageSession;
 }
        static TransportTransactionMode GetRequiredTransactionMode(Settings settings, TransportInfrastructure transportInfrastructure)
        {
            var transportTransactionSupport = transportInfrastructure.TransactionMode;

            //if user haven't asked for a explicit level use what the transport supports
            if (!settings.UserHasProvidedTransportTransactionMode)
            {
                return(transportTransactionSupport);
            }

            var requestedTransportTransactionMode = settings.UserTransportTransactionMode;

            if (requestedTransportTransactionMode > transportTransactionSupport)
            {
                throw new Exception($"Requested transaction mode `{requestedTransportTransactionMode}` can't be satisfied since the transport only supports `{transportTransactionSupport}`");
            }

            return(requestedTransportTransactionMode);
        }
 public RunningEndpointInstance(SettingsHolder settings, ContainerComponent containerComponent, ReceiveComponent receiveComponent, FeatureComponent featureComponent, IMessageSession messageSession, TransportInfrastructure transportInfrastructure)
 {
     this.settings                = settings;
     this.containerComponent      = containerComponent;
     this.receiveComponent        = receiveComponent;
     this.featureComponent        = featureComponent;
     this.messageSession          = messageSession;
     this.transportInfrastructure = transportInfrastructure;
 }
 protected TransportComponent(TransportInfrastructure transportInfrastructure, QueueBindings queueBindings)
 {
     this.transportInfrastructure = transportInfrastructure;
     QueueBindings = queueBindings;
 }
 public void RegisterTransportInfrastructureForBackwardsCompatibility(TransportInfrastructure transportInfrastructure)
 {
     settings.Set(transportInfrastructure);
 }
 public RunningEndpointInstance(SettingsHolder settings, IBuilder builder, List <TransportReceiver> receivers, FeatureRunner featureRunner, IMessageSession messageSession, TransportInfrastructure transportInfrastructure)
 {
     this.settings                = settings;
     this.builder                 = builder;
     this.receivers               = receivers;
     this.featureRunner           = featureRunner;
     this.messageSession          = messageSession;
     this.transportInfrastructure = transportInfrastructure;
 }
        public StartableEndpoint(SettingsHolder settings, IBuilder builder, FeatureActivator featureActivator, PipelineConfiguration pipelineConfiguration, IEventAggregator eventAggregator, TransportInfrastructure transportInfrastructure, CriticalError criticalError)
        {
            this.criticalError           = criticalError;
            this.settings                = settings;
            this.builder                 = builder;
            this.featureActivator        = featureActivator;
            this.pipelineConfiguration   = pipelineConfiguration;
            this.eventAggregator         = eventAggregator;
            this.transportInfrastructure = transportInfrastructure;

            pipelineCache = new PipelineCache(builder, settings);

            messageSession = new MessageSession(new RootContext(builder, pipelineCache, eventAggregator));
        }