TopologySectionInternal CreateSectionForSend(string destination)
        {
            var inputQueueAddress = addressingLogic.Apply(destination, EntityType.Queue);

            RuntimeNamespaceInfo[] namespaces = null;
            if (inputQueueAddress.HasSuffix && inputQueueAddress.Suffix != defaultNameSpaceAlias) // sending to specific namespace
            {
                if (inputQueueAddress.HasConnectionString)
                {
                    namespaces = new[]
                    {
                        new RuntimeNamespaceInfo(inputQueueAddress.Suffix, inputQueueAddress.Suffix, NamespacePurpose.Routing)
                    };
                }
                else
                {
                    NamespaceInfo configured = null;
                    foreach (var namespaceConfiguration in namespaceConfigurations)
                    {
                        if (namespaceConfiguration.Alias == inputQueueAddress.Suffix)
                        {
                            configured = namespaceConfiguration;
                        }
                    }

                    if (configured != null)
                    {
                        namespaces = new[]
                        {
                            new RuntimeNamespaceInfo(configured.Alias, configured.Connection, configured.Purpose)
                        };
                    }
                }
            }
            else
            {
                NamespaceInfo configured = null;
                foreach (var namespaceConfiguration in namespaceConfigurations)
                {
                    if (namespaceConfiguration.RegisteredEndpoints.Contains(destination, StringComparer.OrdinalIgnoreCase))
                    {
                        configured = namespaceConfiguration;
                    }
                }

                if (configured != null)
                {
                    namespaces = new[]
                    {
                        new RuntimeNamespaceInfo(configured.Alias, configured.Connection, configured.Purpose)
                    };
                }
                else // sending to the partition
                {
                    namespaces = namespacePartitioningStrategy.GetNamespaces(PartitioningIntent.Sending).ToArray();
                }
            }

            if (namespaces == null)
            {
                throw new Exception($"Could not determine namespace for destination `{destination}`.");
            }

            var entities = new List <EntityInfoInternal>(namespaces.Length);

            foreach (var n in namespaces)
            {
                entities.Add(new EntityInfoInternal
                {
                    Path      = inputQueueAddress.Name,
                    Type      = EntityType.Queue,
                    Namespace = n
                });
            }

            return(new TopologySectionInternal
            {
                Namespaces = namespaces,
                Entities = entities
            });
        }
Exemplo n.º 2
0
 /// <summary></summary>
 public RuntimeNamespaceInfo(string alias, string connectionString, NamespacePurpose purpose = NamespacePurpose.Partitioning, NamespaceMode mode = NamespaceMode.Active)
 {
     info = new NamespaceInfo(alias, connectionString, purpose);
     Mode = mode;
 }