/// <summary> /// Configures the outbox to use TransactionScope instead of SqlTransaction. This allows wrapping the /// the outbox transaction (and synchronized storage session it manages) and other database transactions in a single scope - provided that /// Distributed Transaction Coordinator (DTC) infrastructure is configured. /// </summary> /// <param name="outboxSettings">Outbox settings.</param> /// <param name="isolationLevel">Isolation level to use. Only levels Read Committed, Repeatable Read and Serializable are supported.</param> public static void UseTransactionScope(this OutboxSettings outboxSettings, IsolationLevel isolationLevel) { if (isolationLevel == IsolationLevel.Chaos || isolationLevel == IsolationLevel.ReadUncommitted || isolationLevel == IsolationLevel.Snapshot || isolationLevel == IsolationLevel.Unspecified) { throw new Exception($"Isolation level {isolationLevel} is not supported."); } outboxSettings.GetSettings().Set(SqlOutboxFeature.UseTransactionScope, true); outboxSettings.GetSettings().Set(SqlOutboxFeature.TransactionScopeIsolationLevel, isolationLevel); }
/// <summary> /// Sets the time to keep the deduplication data to the specified time span. /// </summary> /// <param name="configuration">The configuration being extended.</param> /// <param name="timeToKeepDeduplicationData">The time to keep the deduplication data. /// The cleanup process removes entries older than the specified time to keep deduplication data. The time span cannot be negative or zero.</param> public static void KeepDeduplicationDataFor(this OutboxSettings configuration, TimeSpan timeToKeepDeduplicationData) { Guard.AgainstNull(nameof(configuration), configuration); Guard.AgainstNegativeAndZero(nameof(timeToKeepDeduplicationData), timeToKeepDeduplicationData); configuration.GetSettings().Set(SqlOutboxFeature.TimeToKeepDeduplicationData, timeToKeepDeduplicationData); }
/// <summary> /// Sets the frequency to run the deduplication data cleanup task. /// </summary> /// <param name="configuration">The configuration being extended.</param> /// <param name="frequencyToRunDeduplicationDataCleanup">The frequency to run the deduplication data cleanup task. The time span cannot be negative or sero.</param> public static void RunDeduplicationDataCleanupEvery(this OutboxSettings configuration, TimeSpan frequencyToRunDeduplicationDataCleanup) { Guard.AgainstNull(nameof(configuration), configuration); Guard.AgainstNegativeAndZero(nameof(frequencyToRunDeduplicationDataCleanup), frequencyToRunDeduplicationDataCleanup); configuration.GetSettings().Set(SqlOutboxFeature.FrequencyToRunDeduplicationDataCleanup, frequencyToRunDeduplicationDataCleanup); }
/// <summary> /// Sets the time to keep the deduplication data to the specified time span. /// </summary> /// <param name="configuration">The configuration being extended</param> /// <param name="timeToKeepDeduplicationData">The time to keep the deduplication data. /// The cleanup process removes entries older than the specified time to keep deduplication data, therefore the time span cannot be negative</param> public static void SetTimeToKeepDeduplicationData(this OutboxSettings configuration, TimeSpan timeToKeepDeduplicationData) { Guard.AgainstNull(nameof(configuration), configuration); Guard.AgainstNegativeAndZero(nameof(timeToKeepDeduplicationData), timeToKeepDeduplicationData); configuration.GetSettings().Set(OutboxPersistenceFeature.TimeToKeepDeduplicationEntries, timeToKeepDeduplicationData); }
/// <summary> /// Configures the outbox to use specific transaction level. /// Only levels Read Committed, Repeatable Read and Serializable are supported. /// </summary> public static void TransactionIsolationLevel(this OutboxSettings outboxSettings, System.Data.IsolationLevel isolationLevel) { if (isolationLevel == System.Data.IsolationLevel.Chaos || isolationLevel == System.Data.IsolationLevel.ReadUncommitted || isolationLevel == System.Data.IsolationLevel.Snapshot || isolationLevel == System.Data.IsolationLevel.Unspecified) { throw new Exception($"Isolation level {isolationLevel} is not supported."); } outboxSettings.GetSettings().Set(SqlOutboxFeature.AdoTransactionIsolationLevel, isolationLevel); }
/// <summary> /// Enables outbox pessimistic mode in which Outbox record is created prior to invoking the message handler. As a result, /// the likelihood of invoking the message handler multiple times in case of duplicate messages is much lower. /// /// Note that the outbox always ensures that the transactional side effects of message processing are applied once. The pessimistic /// mode only affects non-transactional side effects. In the pessimistic mode the latter are less likely to be applied /// multiple times but that can still happen e.g. when a message processing attempt is interrupted. /// </summary> public static void UsePessimisticConcurrencyControl(this OutboxSettings outboxSettings) { outboxSettings.GetSettings().Set(SqlOutboxFeature.ConcurrencyMode, true); }
/// <summary> /// Disable the built-in outbox deduplication records cleanup. /// </summary> public static void DisableCleanup(this OutboxSettings configuration) { Guard.AgainstNull(nameof(configuration), configuration); configuration.GetSettings().Set(SqlOutboxFeature.DisableCleanup, true); }
/// <summary> /// Sets the frequency to run the deduplication data cleanup task. /// </summary> /// <param name="configuration">The configuration being extended</param> /// <param name="frequencyToRunDeduplicationDataCleanup">The frequency to run the deduplication data cleanup task. By specifying a negative time span (-1) the cleanup task will never run.</param> public static void SetFrequencyToRunDeduplicationDataCleanup(this OutboxSettings configuration, TimeSpan frequencyToRunDeduplicationDataCleanup) { Guard.AgainstNull(nameof(configuration), configuration); Guard.AgainstZero(nameof(frequencyToRunDeduplicationDataCleanup), frequencyToRunDeduplicationDataCleanup); configuration.GetSettings().Set(OutboxPersistenceFeature.FrequencyToRunDeduplicationDataCleanup, frequencyToRunDeduplicationDataCleanup); }
/// <summary> /// Sets the time to live for outbox deduplication records /// </summary> public static void TimeToKeepOutboxDeduplicationData(this OutboxSettings outboxSettings, TimeSpan timeToKeepOutboxDeduplicationData) { Guard.AgainstNegativeAndZero(nameof(timeToKeepOutboxDeduplicationData), timeToKeepOutboxDeduplicationData); outboxSettings.GetSettings().Set(SettingsKeys.OutboxTimeToLiveInSeconds, (int)timeToKeepOutboxDeduplicationData.TotalSeconds); }
/// <summary> /// Specifies how long the outbox should keep message data in storage to be able to deduplicate. /// </summary> /// <param name="settings">The outbox settings.</param> /// <param name="time"> /// Defines the <see cref="TimeSpan"/> which indicates how long the outbox deduplication entries should be kept. /// For example, if <code>TimeSpan.FromDays(1)</code> is used, the deduplication entries are kept for no longer than one day. /// It is not possible to use a negative or zero TimeSpan value. /// </param> public static OutboxSettings TimeToKeepDeduplicationData(this OutboxSettings settings, TimeSpan time) { Guard.AgainstNegativeAndZero(nameof(time), time); settings.GetSettings().Set(NonDurableOutboxPersistence.TimeToKeepDeduplicationEntries, time); return(settings); }
/// <summary> /// Sets the frequency to clean up deduplication data. /// </summary> /// <param name="configuration">The <see cref="OutboxSettings" /> being extended.</param> /// <param name="frequencyToRunDeduplicationDataCleanup"> /// A positive <see cref="TimeSpan" /> representing the frequency to clean up deduplication data, /// or <see cref="System.Threading.Timeout.InfiniteTimeSpan" /> (-1 milliseconds) to disable deduplication data clean up. /// </param> /// <remarks>By default, deduplication data is cleaned up every 60 seconds.</remarks> /// <remarks> /// When document expiration is enabled on the database, it is recommended to disable deduplication data clean up /// by specifying <see cref="System.Threading.Timeout.InfiniteTimeSpan" /> for /// <paramref name="frequencyToRunDeduplicationDataCleanup" />. /// </remarks> public static void SetFrequencyToRunDeduplicationDataCleanup(this OutboxSettings configuration, TimeSpan frequencyToRunDeduplicationDataCleanup) => configuration.GetSettings().SetFrequencyToRunDeduplicationDataCleanup(frequencyToRunDeduplicationDataCleanup);
/// <summary> /// Sets the <see cref="TimeSpan" /> to keep deduplication data. /// </summary> /// <param name="configuration">The <see cref="OutboxSettings" /> being extended.</param> /// <param name="timeToKeepDeduplicationData">A positive <see cref="TimeSpan" /> to keep deduplication data.</param> /// <remarks>By default, deduplication data is kept for seven days.</remarks> public static void SetTimeToKeepDeduplicationData(this OutboxSettings configuration, TimeSpan timeToKeepDeduplicationData) => configuration.GetSettings().SetTimeToKeepDeduplicationData(timeToKeepDeduplicationData);
/// <summary> /// Configures the outbox to use TransactionScope instead of SqlTransaction. This allows wrapping the /// the outbox transaction (and synchronized storage session it manages) and other database transactions in a single scope - provided that /// Distributed Transaction Coordinator (DTC) infrastructure is configured. /// </summary> public static void UseTransactionScope(this OutboxSettings outboxSettings) { outboxSettings.GetSettings().Set(SqlOutboxFeature.TransactionMode, true); }