Exemplo n.º 1
0
        internal SqlServerTransportInfrastructure(string catalog, SettingsHolder settings, string connectionString, Func <string> localAddress, Func <LogicalAddress> logicalAddress, bool isEncrypted)
        {
            this.settings         = settings;
            this.connectionString = connectionString;
            this.localAddress     = localAddress;
            this.logicalAddress   = logicalAddress;
            this.isEncrypted      = isEncrypted;

            if (settings.HasSetting(SettingsKeys.DisableNativePubSub))
            {
                OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Unicast, OutboundRoutingType.Unicast);
            }
            else
            {
                OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Multicast, OutboundRoutingType.Unicast);
            }

            settings.TryGet(SettingsKeys.DefaultSchemaSettingsKey, out string defaultSchemaOverride);

            var queueSchemaSettings = settings.GetOrDefault <QueueSchemaAndCatalogSettings>();

            addressTranslator    = new QueueAddressTranslator(catalog, "dbo", defaultSchemaOverride, queueSchemaSettings);
            tableBasedQueueCache = new TableBasedQueueCache(addressTranslator, !isEncrypted);
            connectionFactory    = CreateConnectionFactory();

            //Configure the schema and catalog for logical endpoint-based routing
            var schemaAndCatalogSettings = settings.GetOrCreate <EndpointSchemaAndCatalogSettings>();

            settings.GetOrCreate <EndpointInstances>().AddOrReplaceInstances("SqlServer", schemaAndCatalogSettings.ToEndpointInstances());

            var pubSubSettings        = settings.GetOrCreate <SubscriptionSettings>();
            var subscriptionTableName = pubSubSettings.SubscriptionTable.Qualify(defaultSchemaOverride ?? "dbo", catalog);

            // necessary evil for acceptance tests
            if (settings.TryGet <Action <string> >(SettingsKeys.SubscriptionTableQuotedQualifiedNameSetter, out var action))
            {
                action(subscriptionTableName.QuotedQualifiedName);
            }

            subscriptionStore = new PolymorphicSubscriptionStore(new SubscriptionTable(subscriptionTableName.QuotedQualifiedName, connectionFactory));
            var timeToCacheSubscriptions = pubSubSettings.TimeToCacheSubscriptions;

            if (timeToCacheSubscriptions.HasValue)
            {
                subscriptionStore = new CachedSubscriptionStore(subscriptionStore, timeToCacheSubscriptions.Value);
            }
            var subscriptionTableCreator = new SubscriptionTableCreator(subscriptionTableName, connectionFactory);

            settings.Set(subscriptionTableCreator);
        }
Exemplo n.º 2
0
        public async Task ConfigureSubscriptions(string catalog, CancellationToken cancellationToken = default)
        {
            var pubSubSettings          = transport.Subscriptions;
            var subscriptionStoreSchema = string.IsNullOrWhiteSpace(transport.DefaultSchema) ? "dbo" : transport.DefaultSchema;
            var subscriptionTableName   = pubSubSettings.SubscriptionTableName.Qualify(subscriptionStoreSchema, catalog);

            subscriptionStore = new PolymorphicSubscriptionStore(new SubscriptionTable(subscriptionTableName.QuotedQualifiedName, connectionFactory));

            if (pubSubSettings.DisableCaching == false)
            {
                subscriptionStore = new CachedSubscriptionStore(subscriptionStore, pubSubSettings.CacheInvalidationPeriod);
            }

            if (hostSettings.SetupInfrastructure)
            {
                await new SubscriptionTableCreator(subscriptionTableName, connectionFactory).CreateIfNecessary(cancellationToken).ConfigureAwait(false);
            }

            transport.Testing.SubscriptionTable = subscriptionTableName.QuotedQualifiedName;
        }