/// <summary> /// Enables the outbox feature /// </summary> public static OutboxSettings EnableOutbox(this BusConfiguration config) { var outboxSettings = new OutboxSettings(config.Settings); config.Transactions() .DisableDistributedTransactions() .DoNotWrapHandlersExecutionInATransactionScope(); config.EnableFeature<Features.Outbox>(); return outboxSettings; }
/// <summary> /// Enables the outbox feature. /// </summary> /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param> public static OutboxSettings EnableOutbox(this EndpointConfiguration config) { Guard.AgainstNull(nameof(config), config); var outboxSettings = new OutboxSettings(config.Settings); config.Settings.SetDefault<TransportTransactionMode>(TransportTransactionMode.ReceiveOnly); config.EnableFeature<Features.Outbox>(); return outboxSettings; }
public static void WithEFCoreOutbox <T>(this IServiceRegistrar services, Action <EFCoreOutbox.OutboxSettings> config ) where T : DbContext { OutboxSettings settings = new OutboxSettings(); if (config != null) { config.Invoke(settings); } services.AddSingleton <OutboxSettings>(settings); services.AddSingleton <IOutbox, Outbox <T> >(true); services.AddTransient <IOutboxSession, OutboxSession <T> >(); }
/// <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. /// /// Uses the default isolation level (Serializable). /// </summary> public static void UseTransactionScope(this OutboxSettings outboxSettings) { UseTransactionScope(outboxSettings, IsolationLevel.Serializable); }
/// <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); }
public static OutboxSettings TimeToKeepDeduplicationData(this OutboxSettings settings, TimeSpan time) { throw new NotSupportedException(); }
/// <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); }