Represents a logical address (independent of transport).
 public Configuration(LogicalAddress logicalAddress,
                      string queueNameBase,
                      string localAddress,
                      string instanceSpecificQueue,
                      TransportTransactionMode transactionMode,
                      PushRuntimeSettings pushRuntimeSettings,
                      bool purgeOnStartup,
                      Notification <ReceivePipelineCompleted> pipelineCompletedSubscribers,
                      bool isSendOnlyEndpoint,
                      List <Type> executeTheseHandlersFirst,
                      MessageHandlerRegistry messageHandlerRegistry,
                      bool createQueues, TransportSeam transportSeam)
 {
     LogicalAddress               = logicalAddress;
     QueueNameBase                = queueNameBase;
     LocalAddress                 = localAddress;
     InstanceSpecificQueue        = instanceSpecificQueue;
     TransactionMode              = transactionMode;
     PushRuntimeSettings          = pushRuntimeSettings;
     PurgeOnStartup               = purgeOnStartup;
     IsSendOnlyEndpoint           = isSendOnlyEndpoint;
     PipelineCompletedSubscribers = pipelineCompletedSubscribers;
     ExecuteTheseHandlersFirst    = executeTheseHandlersFirst;
     satelliteDefinitions         = new List <SatelliteDefinition>();
     this.messageHandlerRegistry  = messageHandlerRegistry;
     CreateQueues                 = createQueues;
     this.transportSeam           = transportSeam;
 }
示例#2
0
        public override string ToTransportAddress(LogicalAddress logicalAddress)
        {
            string machine;

            if (!logicalAddress.EndpointInstance.Properties.TryGetValue("machine", out machine))
            {
                machine = RuntimeEnvironment.MachineName;
            }
            string queueName;

            if (!logicalAddress.EndpointInstance.Properties.TryGetValue("queue", out queueName))
            {
                queueName = logicalAddress.EndpointInstance.Endpoint;
            }
            var queue = new StringBuilder(queueName);

            if (logicalAddress.EndpointInstance.Discriminator != null)
            {
                queue.Append("-" + logicalAddress.EndpointInstance.Discriminator);
            }
            if (logicalAddress.Qualifier != null)
            {
                queue.Append("." + logicalAddress.Qualifier);
            }
            return(queue + "@" + machine);
        }
示例#3
0
        internal Receiving()
        {
            EnableByDefault();
            Prerequisite(c => !c.Settings.GetOrDefault <bool>("Endpoint.SendOnly"), "Endpoint is configured as send-only");
            Defaults(s =>
            {
                var transportInfrastructure = s.Get <TransportInfrastructure>();
                var discriminator           = s.GetOrDefault <string>("EndpointInstanceDiscriminator");
                var baseQueueName           = s.GetOrDefault <string>("BaseInputQueueName") ?? s.EndpointName();

                var mainInstance = transportInfrastructure.BindToLocalEndpoint(new EndpointInstance(s.EndpointName()));

                var mainLogicalAddress = LogicalAddress.CreateLocalAddress(baseQueueName, mainInstance.Properties);
                s.SetDefault <LogicalAddress>(mainLogicalAddress);

                var mainAddress = transportInfrastructure.ToTransportAddress(mainLogicalAddress);
                s.SetDefault("NServiceBus.SharedQueue", mainAddress);

                if (discriminator != null)
                {
                    var instanceSpecificAddress = transportInfrastructure.ToTransportAddress(mainLogicalAddress.CreateIndividualizedAddress(discriminator));
                    s.SetDefault("NServiceBus.EndpointSpecificQueue", instanceSpecificAddress);
                }
            });
        }
示例#4
0
        public override string ToTransportAddress(LogicalAddress logicalAddress)
        {
            var address = logicalAddress.EndpointInstance.Endpoint;

            PathChecker.ThrowForBadPath(address, "endpoint name");

            var discriminator = logicalAddress.EndpointInstance.Discriminator;

            if (!string.IsNullOrEmpty(discriminator))
            {
                PathChecker.ThrowForBadPath(discriminator, "endpoint discriminator");

                address += "-" + discriminator;
            }

            var qualifier = logicalAddress.Qualifier;

            if (!string.IsNullOrEmpty(qualifier))
            {
                PathChecker.ThrowForBadPath(qualifier, "address qualifier");

                address += "-" + qualifier;
            }

            return(address);
        }
        public static Configuration PrepareConfiguration(Settings settings, TransportSeam transportSeam)
        {
            var isSendOnlyEndpoint = settings.IsSendOnlyEndpoint;

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

            var endpointName   = settings.EndpointName;
            var discriminator  = settings.EndpointInstanceDiscriminator;
            var queueNameBase  = settings.CustomLocalAddress ?? endpointName;
            var purgeOnStartup = settings.PurgeOnStartup;

            var transportInfrastructure = transportSeam.TransportInfrastructure;

            //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, transportInfrastructure);

            var pushRuntimeSettings = settings.PushRuntimeSettings;

            var receiveConfiguration = new Configuration(
                logicalAddress,
                queueNameBase,
                localAddress,
                instanceSpecificQueue,
                transactionMode,
                pushRuntimeSettings,
                purgeOnStartup,
                settings.PipelineCompletedSubscribers ?? new Notification <ReceivePipelineCompleted>(),
                isSendOnlyEndpoint,
                settings.ExecuteTheseHandlersFirst,
                settings.MessageHandlerRegistry,
                settings.ShouldCreateQueues,
                transportSeam);

            settings.RegisterReceiveConfigurationForBackwardsCompatibility(receiveConfiguration);

            return(receiveConfiguration);
        }
示例#6
0
        public override string ToTransportAddress(LogicalAddress logicalAddress)
        {
            var queue = new StringBuilder(logicalAddress.EndpointInstance.Endpoint);

            if (logicalAddress.EndpointInstance.Discriminator != null)
            {
                queue.Append("-" + logicalAddress.EndpointInstance.Discriminator);
            }
            if (logicalAddress.Qualifier != null)
            {
                queue.Append("_" + logicalAddress.Qualifier);
            }
            return(queue.ToString());
        }
        public static RoutingComponent Initialize(
            Configuration configuration,
            TransportSeam transportSeam,
            ReceiveComponent.Configuration receiveConfiguration,
            Conventions conventions,
            PipelineSettings pipelineSettings)
        {
            var distributionPolicy  = configuration.DistributionPolicy;
            var unicastRoutingTable = configuration.UnicastRoutingTable;
            var endpointInstances   = configuration.EndpointInstances;

            foreach (var distributionStrategy in configuration.CustomDistributionStrategies)
            {
                distributionPolicy.SetDistributionStrategy(distributionStrategy);
            }

            configuration.ConfiguredUnicastRoutes?.Apply(unicastRoutingTable, conventions);

            var isSendOnlyEndpoint = receiveConfiguration.IsSendOnlyEndpoint;

            if (!isSendOnlyEndpoint)
            {
                pipelineSettings.Register(
                    new ApplyReplyToAddressBehavior(
                        receiveConfiguration.LocalAddress,
                        receiveConfiguration.InstanceSpecificQueue,
                        configuration.PublicReturnAddress),
                    "Applies the public reply to address to outgoing messages");
            }

            var sendRouter = new UnicastSendRouter(
                isSendOnlyEndpoint,
                receiveConfiguration?.QueueNameBase,
                receiveConfiguration?.InstanceSpecificQueue,
                distributionPolicy,
                unicastRoutingTable,
                endpointInstances,
                i => transportSeam.TransportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)));

            if (configuration.EnforceBestPractices)
            {
                EnableBestPracticeEnforcement(pipelineSettings, new Validations(conventions));
            }

            return(new RoutingComponent(
                       sendRouter,
                       configuration.EnforceBestPractices));
        }
        public override string ToTransportAddress(LogicalAddress logicalAddress)
        {
            var queueName = logicalAddress.EndpointInstance.Endpoint;
            var queue     = new StringBuilder(queueName);

            if (logicalAddress.EndpointInstance.Discriminator != null)
            {
                queue.Append("-" + logicalAddress.EndpointInstance.Discriminator);
            }

            if (logicalAddress.Qualifier != null)
            {
                queue.Append("-" + logicalAddress.Qualifier);
            }

            return(QueueNameHelper.GetSanitizedQueueName(queue, queueName));
        }
示例#9
0
        public static ReceiveConfiguration Build(ReadOnlySettings settings, TransportComponent.Configuration transportConfiguration)
        {
            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 = transportConfiguration.BindToLocalEndpoint(new EndpointInstance(endpointName)).Properties;

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

            var localAddress = transportConfiguration.ToTransportAddress(logicalAddress);

            string instanceSpecificQueue = null;

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

            var transactionMode = GetRequiredTransactionMode(settings);

            var pushRuntimeSettings = GetDequeueLimitations(settings);

            return(new ReceiveConfiguration(
                       logicalAddress,
                       queueNameBase,
                       localAddress,
                       instanceSpecificQueue,
                       transactionMode,
                       pushRuntimeSettings,
                       purgeOnStartup,
                       settings.GetOrDefault <Notification <ReceivePipelineCompleted> >() ?? new Notification <ReceivePipelineCompleted>()));
        }
        public ReceiveConfiguration(LogicalAddress logicalAddress,
                                    string queueNameBase,
                                    string localAddress,
                                    string instanceSpecificQueue,
                                    TransportTransactionMode transactionMode,
                                    PushRuntimeSettings pushRuntimeSettings,
                                    bool purgeOnStartup)
        {
            LogicalAddress        = logicalAddress;
            QueueNameBase         = queueNameBase;
            LocalAddress          = localAddress;
            InstanceSpecificQueue = instanceSpecificQueue;
            TransactionMode       = transactionMode;
            PushRuntimeSettings   = pushRuntimeSettings;
            PurgeOnStartup        = purgeOnStartup;

            satelliteDefinitions = new List <SatelliteDefinition>();
        }
 public override string ToTransportAddress(LogicalAddress logicalAddress)
 {
     string machine;
     if (!logicalAddress.EndpointInstance.Properties.TryGetValue("machine", out machine))
     {
         machine = RuntimeEnvironment.MachineName;
     }
     string queueName;
     if (!logicalAddress.EndpointInstance.Properties.TryGetValue("queue", out queueName))
     {
         queueName = logicalAddress.EndpointInstance.Endpoint;
     }
     var queue = new StringBuilder(queueName);
     if (logicalAddress.EndpointInstance.Discriminator != null)
     {
         queue.Append("-" + logicalAddress.EndpointInstance.Discriminator);
     }
     if (logicalAddress.Qualifier != null)
     {
         queue.Append("." + logicalAddress.Qualifier);
     }
     return queue + "@" + machine;
 }
示例#12
0
 bool Equals(LogicalAddress other)
 {
     return(string.Equals(Qualifier, other.Qualifier) && Equals(EndpointInstance, other.EndpointInstance));
 }
示例#13
0
 public override string ToTransportAddress(LogicalAddress logicalAddress)
 {
     return Path.Combine(logicalAddress.EndpointInstance.Endpoint.ToString(),
         logicalAddress.EndpointInstance.Discriminator ?? "",
         logicalAddress.Qualifier ?? "");
 }
示例#14
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);
            }
        }
示例#15
0
 public string ToTransportAddress(LogicalAddress logicalAddress)
 {
     return(transportInfrastructure.ToTransportAddress(logicalAddress));
 }
        protected override void Setup(FeatureConfigurationContext context)
        {
            var transportInfrastructure = context.Settings.Get <TransportInfrastructure>();
            var routingEngineConfig     = context.Settings.Get <BlueprintAccessConfiguration>();
            var routingEngine           = routingEngineConfig.Create();

            var outboundRoutingPolicy = context.Settings.Get <TransportInfrastructure>().OutboundRoutingPolicy;

            var evaluator = new BlueprintBasedRouteGenerator(context.Settings.EndpointName());
            var router    = new UnicastRouter(evaluator,
                                              context.Settings.Get <EndpointInstances>(),
                                              context.Settings.Get <DistributionPolicy>(),
                                              instance => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(instance)));

            context.RegisterStartupTask(new EngineManagementTask(routingEngine, map => evaluator.UpdateSourceData(map)));

            context.Pipeline.Register(new RouteToSitesBehavior(), "Adds site information to outgoing messages.");

            // if the transport provides native pub/sub support, don't plug in the FileBased pub/sub storage.
            if (outboundRoutingPolicy.Publishes == OutboundRoutingType.Unicast)
            {
                context.Pipeline.Replace("UnicastPublishRouterConnector", new PublishRoutingConnector(router));
                context.Pipeline.Replace("MessageDrivenSubscribeTerminator", new NullSubscribeTerminator(), "handles subscribe operations");
                context.Pipeline.Replace("MessageDrivenUnsubscribeTerminator", new NullUnsubscribeTerminator(), "handles ubsubscribe operations");
            }
            if (outboundRoutingPolicy.Sends == OutboundRoutingType.Unicast)
            {
                context.Pipeline.Replace("UnicastSendRouterConnector", new SendRoutingConnector(router));
            }
            else
            {
                context.Pipeline.Replace("UnicastSendRouterConnector", new MulticastSendRoutingConnector());
            }
        }
示例#17
0
 public override string ToTransportAddress(LogicalAddress logicalAddress)
 {
     return(logicalAddress.EndpointInstance.Endpoint);
 }
示例#18
0
 string CustomTranslationRule(LogicalAddress endpointInstanceName)
 {
     throw new NotImplementedException();
 }
示例#19
0
 bool Equals(LogicalAddress other)
 {
     return string.Equals(Qualifier, other.Qualifier) && Equals(EndpointInstance, other.EndpointInstance);
 }
示例#20
0
 public override string ToTransportAddress(LogicalAddress logicalAddress)
 {
     throw new NotImplementedException();
 }
示例#21
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);
            }
        }
示例#22
0
 public override string ToTransportAddress(LogicalAddress logicalAddress)
 {
     return null;
 }