Exemple #1
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 static RoutingComponent Initialize(Configuration configuration,
                                                  TransportComponent.Configuration transportConfiguration,
                                                  ReceiveConfiguration receiveConfiguration,
                                                  Conventions conventions,
                                                  PipelineSettings pipelineSettings)
        {
            var distributionPolicy  = configuration.DistributionPolicy;
            var unicastRoutingTable = configuration.UnicastRoutingTable;
            var endpointInstances   = configuration.EndpointInstances;

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

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

            var isSendOnlyEndpoint = receiveConfiguration == null;

            if (isSendOnlyEndpoint == false)
            {
                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 => transportConfiguration.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)));

            return(new RoutingComponent(
                       unicastRoutingTable,
                       distributionPolicy,
                       endpointInstances,
                       configuration.Publishers,
                       sendRouter,
                       configuration.EnforceBestPractices,
                       new Validations(conventions)));
        }