protected override void Setup(FeatureConfigurationContext context)
        {
            var store = DocumentStoreManager.GetDocumentStore <StorageType.Subscriptions>(context.Settings);

            store.Listeners.RegisterListener(new SubscriptionV1toV2Converter());

            var persister = new SubscriptionPersister(store);

            if (context.Settings.GetOrDefault <bool>(RavenDbSubscriptionSettingsExtensions.DoNotAggressivelyCacheSubscriptionsSettingsKey))
            {
                persister.DisableAggressiveCaching = true;
            }

            if (!context.Settings.TryGet(RavenDbSubscriptionSettingsExtensions.LegacySubscriptionVersioningKey, out bool useLegacy))
            {
                throw new Exception("RavenDB subscription storage requires using either `persistence.DisableSubscriptionVersioning()` or `persistence.UseLegacyVersionedSubscriptions()` to determine whether legacy versioned subscriptions should be used.");
            }

            if (useLegacy)
            {
                // This is the default in the persister class, to facilitate tests verifying legacy behavior
                Log.Warn("RavenDB Persistence is using legacy versioned subscription storage. This capability will be removed in NServiceBus.RavenDB 6.0.0. Subscription documents need to be converted to the new unversioned format, after which `persistence.DisableSubscriptionVersioning()` should be used.");
            }
            else
            {
                persister.SubscriptionIdFormatter = new NonVersionedSubscriptionIdFormatter();
            }

            if (context.Settings.TryGet(RavenDbSubscriptionSettingsExtensions.AggressiveCacheDurationSettingsKey, out TimeSpan aggressiveCacheDuration))
            {
                persister.AggressiveCacheDuration = aggressiveCacheDuration;
            }

            context.Container.ConfigureComponent <ISubscriptionStorage>(_ => persister, DependencyLifecycle.SingleInstance);
        }
        protected override void Setup(FeatureConfigurationContext context)
        {
            context.Container.ConfigureComponent <RavenDBSynchronizedStorageAdapter>(DependencyLifecycle.SingleInstance);
            context.Container.ConfigureComponent <RavenDBSynchronizedStorage>(DependencyLifecycle.SingleInstance);

            IOpenRavenSessionsInPipeline sessionCreator;

            // Check to see if the user provided us with a shared session to work with before we go and create our own to inject into the pipeline
            var getAsyncSessionFunc         = context.Settings.GetOrDefault <Func <IDictionary <string, string>, IAsyncDocumentSession> >(RavenDbSettingsExtensions.SharedAsyncSessionSettingsKey);
            var getAsyncSessionFuncObsolete = context.Settings.GetOrDefault <Func <IAsyncDocumentSession> >(RavenDbSettingsExtensions.SharedAsyncSessionSettingsKey + ".Obsolete");

            if (getAsyncSessionFunc != null)
            {
                sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFunc);
            }
            else if (getAsyncSessionFuncObsolete != null)
            {
                sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFuncObsolete);
            }
            else
            {
                var store        = DocumentStoreManager.GetDocumentStore <StorageType.Sagas>(context.Settings);
                var storeWrapper = new DocumentStoreWrapper(store);

                var dbNameConvention = context.Settings.GetOrDefault <Func <IDictionary <string, string>, string> >("RavenDB.SetMessageToDatabaseMappingConvention");
                sessionCreator = new OpenRavenSessionByDatabaseName(storeWrapper, dbNameConvention);
            }

            context.Container.RegisterSingleton(sessionCreator);
            context.Pipeline.Register("OpenRavenDbAsyncSession", new OpenAsyncSessionBehavior(sessionCreator), "Makes sure that there is a RavenDB IAsyncDocumentSession available on the pipeline");
        }
        protected override void Setup(FeatureConfigurationContext context)
        {
            DocumentStoreManager.GetUninitializedDocumentStore <StorageType.Outbox>(context.Settings)
            .CreateIndexOnInitialization(new OutboxRecordsIndex());

            var timeToKeepDeduplicationData = context.Settings.GetOrDefault <TimeSpan?>(TimeToKeepDeduplicationData) ?? DeduplicationDataTTLDefault;

            context.Services.AddTransient <IOutboxStorage>(
                sp => new OutboxPersister(context.Settings.EndpointName(), sp.GetRequiredService <IOpenTenantAwareRavenSessions>(), timeToKeepDeduplicationData));

            var frequencyToRunDeduplicationDataCleanup = context.Settings.GetOrDefault <TimeSpan?>(FrequencyToRunDeduplicationDataCleanup) ?? TimeSpan.FromMinutes(1);

            context.RegisterStartupTask(builder =>
            {
                var store = DocumentStoreManager.GetDocumentStore <StorageType.Outbox>(context.Settings, builder);
                return(new OutboxCleaner(new OutboxRecordsCleaner(store), frequencyToRunDeduplicationDataCleanup, timeToKeepDeduplicationData));
            });

            context.Settings.AddStartupDiagnosticsSection(
                "NServiceBus.Persistence.RavenDB.Outbox",
                new
            {
                FrequencyToRunDeduplicationDataCleanup = frequencyToRunDeduplicationDataCleanup,
                TimeToKeepDeduplicationData            = timeToKeepDeduplicationData,
            });
        }
Пример #4
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var doNotCacheSubscriptions = context.Settings.GetOrDefault <bool>(DoNotCacheSubscriptions);
            var cacheSubscriptionsFor   = context.Settings.GetOrDefault <TimeSpan?>(CacheSubscriptionsFor) ?? TimeSpan.FromMinutes(1);

            context.Settings.AddStartupDiagnosticsSection(
                "NServiceBus.Persistence.RavenDB.Subscriptions",
                new
            {
                DoNotCacheSubscriptions = doNotCacheSubscriptions,
                CacheSubscriptionsFor   = cacheSubscriptionsFor,
            });

            context.Container.ConfigureComponent <ISubscriptionStorage>(builder =>
            {
                var store = DocumentStoreManager.GetDocumentStore <StorageType.Subscriptions>(context.Settings, builder);

                return(new SubscriptionPersister(store)
                {
                    DisableAggressiveCaching = doNotCacheSubscriptions,
                    AggressiveCacheDuration = cacheSubscriptionsFor,
                });
            },
                                                                        DependencyLifecycle.SingleInstance);
        }
        protected override void Setup(FeatureConfigurationContext context)
        {
            var store = DocumentStoreManager.GetDocumentStore <StorageType.Timeouts>(context.Settings);

            Helpers.SafelyCreateIndex(store, new TimeoutsIndex());

            context.Container.ConfigureComponent(() => new TimeoutPersister(store), DependencyLifecycle.InstancePerCall);
            context.Container.ConfigureComponent(() => new QueryTimeouts(store, context.Settings.EndpointName()), DependencyLifecycle.SingleInstance); // Needs to be SingleInstance because it contains cleanup state

            context.Container.ConfigureComponent <QueryCanceller>(DependencyLifecycle.InstancePerCall);
            context.RegisterStartupTask(b => b.Build <QueryCanceller>());
        }
Пример #6
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var store        = DocumentStoreManager.GetDocumentStore <StorageType.Outbox>(context.Settings);
            var endpointName = context.Settings.EndpointName();

            Helpers.SafelyCreateIndex(store, new OutboxRecordsIndex());

            context.Container.ConfigureComponent(b => new OutboxPersister(store, endpointName, b.Build <IOpenRavenSessionsInPipeline>()), DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent(b => new OutboxRecordsCleaner(store), DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent <OutboxCleaner>(DependencyLifecycle.InstancePerCall);

            context.RegisterStartupTask(builder => builder.Build <OutboxCleaner>());
        }
        protected override void Setup(FeatureConfigurationContext context)
        {
            var store = DocumentStoreManager.GetDocumentStore <StorageType.Subscriptions>(context.Settings);

            var persister = new SubscriptionPersister(store);

            if (context.Settings.GetOrDefault <bool>(RavenDbSubscriptionSettingsExtensions.DoNotAggressivelyCacheSubscriptionsSettingsKey))
            {
                persister.DisableAggressiveCaching = true;
            }

            if (context.Settings.TryGet(RavenDbSubscriptionSettingsExtensions.AggressiveCacheDurationSettingsKey, out TimeSpan aggressiveCacheDuration))
            {
                persister.AggressiveCacheDuration = aggressiveCacheDuration;
            }

            context.Container.ConfigureComponent <ISubscriptionStorage>(_ => persister, DependencyLifecycle.SingleInstance);
        }
        protected override void Setup(FeatureConfigurationContext context)
        {
            // Check to see if the user provided us with a shared session to work with before we go and create our own to inject into the pipeline
            var getAsyncSessionFunc = context.Settings.GetOrDefault <Func <IDictionary <string, string>, IAsyncDocumentSession> >(SharedAsyncSession);

            if (getAsyncSessionFunc != null)
            {
                IOpenTenantAwareRavenSessions sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFunc);
                context.Services.AddSingleton(sessionCreator);

                context.Settings.AddStartupDiagnosticsSection(
                    StartupDiagnosticsSectionName,
                    new
                {
                    HasSharedAsyncSession = true,
                });
            }
            else
            {
                context.Services.AddSingleton <IOpenTenantAwareRavenSessions>(sp =>
                {
                    var store            = DocumentStoreManager.GetDocumentStore <StorageType.Sagas>(context.Settings, sp);
                    var storeWrapper     = new DocumentStoreWrapper(store);
                    var dbNameConvention = context.Settings.GetOrDefault <Func <IDictionary <string, string>, string> >(MessageToDatabaseMappingConvention);
                    return(new OpenRavenSessionByDatabaseName(storeWrapper, dbNameConvention));
                });

                context.Settings.AddStartupDiagnosticsSection(
                    StartupDiagnosticsSectionName,
                    new
                {
                    HasSharedAsyncSession = false,
                    HasMessageToDatabaseMappingConvention = context.Settings.HasSetting(MessageToDatabaseMappingConvention),
                });
            }

            var sessionHolder = new CurrentSessionHolder();

            context.Services.AddScoped(_ => sessionHolder.Current);
            context.Pipeline.Register(new CurrentSessionBehavior(sessionHolder), "Manages the lifecycle of the current session holder.");
            context.Services.AddSingleton <ISynchronizedStorage, RavenDBSynchronizedStorage>(provider => new RavenDBSynchronizedStorage(provider.GetService <IOpenTenantAwareRavenSessions>(), sessionHolder));
            context.Services.AddSingleton <ISynchronizedStorageAdapter>(new RavenDBSynchronizedStorageAdapter(sessionHolder));
        }
Пример #9
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            context.Container.ConfigureComponent <RavenDBSynchronizedStorageAdapter>(DependencyLifecycle.SingleInstance);
            context.Container.ConfigureComponent <RavenDBSynchronizedStorage>(DependencyLifecycle.SingleInstance);

            // Check to see if the user provided us with a shared session to work with before we go and create our own to inject into the pipeline
            var getAsyncSessionFunc = context.Settings.GetOrDefault <Func <IDictionary <string, string>, IAsyncDocumentSession> >(SharedAsyncSession);

            if (getAsyncSessionFunc != null)
            {
                IOpenTenantAwareRavenSessions sessionCreator = new OpenRavenSessionByCustomDelegate(getAsyncSessionFunc);
                context.Container.RegisterSingleton(sessionCreator);

                context.Settings.AddStartupDiagnosticsSection(
                    StartupDiagnosticsSectionName,
                    new
                {
                    HasSharedAsyncSession = true,
                });
            }
            else
            {
                context.Container.ConfigureComponent <IOpenTenantAwareRavenSessions>(
                    builder =>
                {
                    var store            = DocumentStoreManager.GetDocumentStore <StorageType.Sagas>(context.Settings, builder);
                    var storeWrapper     = new DocumentStoreWrapper(store);
                    var dbNameConvention = context.Settings.GetOrDefault <Func <IDictionary <string, string>, string> >(MessageToDatabaseMappingConvention);
                    return(new OpenRavenSessionByDatabaseName(storeWrapper, dbNameConvention));
                },
                    DependencyLifecycle.SingleInstance);

                context.Settings.AddStartupDiagnosticsSection(
                    StartupDiagnosticsSectionName,
                    new
                {
                    HasSharedAsyncSession = false,
                    HasMessageToDatabaseMappingConvention = context.Settings.HasSetting(MessageToDatabaseMappingConvention),
                });
            }
        }
        protected override void Setup(FeatureConfigurationContext context)
        {
            //var store = DocumentStoreManager.GetDocumentStore<StorageType.Timeouts>(context.Settings);
            DocumentStoreManager.GetUninitializedDocumentStore <StorageType.Timeouts>(context.Settings)
            .CreateIndexOnInitialization(new TimeoutsIndex());

            context.Container.ConfigureComponent(b =>
            {
                var store = DocumentStoreManager.GetDocumentStore <StorageType.Timeouts>(context.Settings, b);
                return(new TimeoutPersister(store));
            }, DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent(b =>
            {
                var store = DocumentStoreManager.GetDocumentStore <StorageType.Timeouts>(context.Settings, b);
                return(new QueryTimeouts(store, context.Settings.EndpointName()));
            }, DependencyLifecycle.SingleInstance); // Needs to be SingleInstance because it contains cleanup state

            context.Container.ConfigureComponent(typeof(QueryCanceller), DependencyLifecycle.InstancePerCall);
            context.RegisterStartupTask(b => b.Build <QueryCanceller>());
        }
Пример #11
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var store = DocumentStoreManager.GetDocumentStore <StorageType.GatewayDeduplication>(context.Settings);

            context.Container.ConfigureComponent(b => new RavenDeduplication(store), DependencyLifecycle.SingleInstance);
        }