From add78b4ea47bc5fef4455fdcfbcda029da0a847e Mon Sep 17 00:00:00 2001 From: Matthias Gernand Date: Tue, 10 Jan 2023 21:16:01 +0100 Subject: [PATCH] Added config switch to enable/disable the in-memory outbox. (#84) --- .../AzureServiceBusMessagingOptions.cs | 10 +++++++++- .../Contributors/TransportContributor.cs | 2 +- .../Contributors/TransportContributor.cs | 5 ++++- .../InMemoryMessagingOptions.cs | 8 ++++++++ .../Contributors/TransportContributor.cs | 2 +- .../RabbitMqMessagingOptions.cs | 8 ++++++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/AzureServiceBusMessagingOptions.cs b/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/AzureServiceBusMessagingOptions.cs index 4e4ca108..81571a56 100644 --- a/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/AzureServiceBusMessagingOptions.cs +++ b/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/AzureServiceBusMessagingOptions.cs @@ -14,9 +14,17 @@ public sealed class AzureServiceBusMessagingOptions /// public AzureServiceBusMessagingOptions() { - ConnectionStrings = new ConnectionStrings(); + this.ConnectionStrings = new ConnectionStrings(); } + /// + /// Gets or sets a value indicating whether the in-memory outbox is enabled. + /// + /// + /// true if the in-memory outbox is enabled; otherwise, false. + /// + public bool InMemoryOutboxEnabled { get; set; } = true; + /// /// Gets or sets the name of the connection string to use. /// diff --git a/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/Contributors/TransportContributor.cs b/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/Contributors/TransportContributor.cs index 5387e5b3..0da1f595 100644 --- a/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/Contributors/TransportContributor.cs +++ b/src/Fluxera.Extensions.Hosting.Modules.Messaging.AzureServiceBus/Contributors/TransportContributor.cs @@ -22,7 +22,7 @@ public void ConfigureTransport(IBusRegistrationConfigurator configurator, IServi configurator.UsingAzureServiceBus((ctx, cfg) => { bool isTransactionalOutboxModuleLoaded = context.Items.ContainsKey("IsTransactionalOutboxModuleLoaded"); - if(!isTransactionalOutboxModuleLoaded) + if(!isTransactionalOutboxModuleLoaded && options.InMemoryOutboxEnabled) { cfg.UseInMemoryOutbox(); } diff --git a/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/Contributors/TransportContributor.cs b/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/Contributors/TransportContributor.cs index 2e30dd35..627c1722 100644 --- a/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/Contributors/TransportContributor.cs +++ b/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/Contributors/TransportContributor.cs @@ -2,6 +2,7 @@ { using System.Text.Json; using Fluxera.Enumeration.SystemTextJson; + using Fluxera.Extensions.Hosting.Modules.Configuration; using Fluxera.Extensions.Hosting.Modules.Messaging.Filters; using Fluxera.Spatial.SystemTextJson; using Fluxera.StronglyTypedId.SystemTextJson; @@ -15,10 +16,12 @@ internal sealed class TransportContributor : ITransportContributor /// public void ConfigureTransport(IBusRegistrationConfigurator configurator, IServiceConfigurationContext context) { + InMemoryMessagingOptions options = context.Services.GetOptions(); + configurator.UsingInMemory((ctx, cfg) => { bool isTransactionalOutboxModuleLoaded = context.Items.ContainsKey("IsTransactionalOutboxModuleLoaded"); - if(!isTransactionalOutboxModuleLoaded) + if(!isTransactionalOutboxModuleLoaded && options.InMemoryOutboxEnabled) { cfg.UseInMemoryOutbox(); } diff --git a/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/InMemoryMessagingOptions.cs b/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/InMemoryMessagingOptions.cs index d1e5a2f3..bfef6e54 100644 --- a/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/InMemoryMessagingOptions.cs +++ b/src/Fluxera.Extensions.Hosting.Modules.Messaging.InMemory/InMemoryMessagingOptions.cs @@ -12,5 +12,13 @@ public sealed class InMemoryMessagingOptions /// Specify the number of concurrent messages that can be consumed (separate from prefetch count). /// public int? ConcurrentMessageLimit { get; set; } + + /// + /// Gets or sets a value indicating whether the in-memory outbox is enabled. + /// + /// + /// true if the in-memory outbox is enabled; otherwise, false. + /// + public bool InMemoryOutboxEnabled { get; set; } = true; } } diff --git a/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/Contributors/TransportContributor.cs b/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/Contributors/TransportContributor.cs index 508982c2..00c6a414 100644 --- a/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/Contributors/TransportContributor.cs +++ b/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/Contributors/TransportContributor.cs @@ -24,7 +24,7 @@ public void ConfigureTransport(IBusRegistrationConfigurator configurator, IServi configurator.UsingRabbitMq((ctx, cfg) => { bool isTransactionalOutboxModuleLoaded = context.Items.ContainsKey("IsTransactionalOutboxModuleLoaded"); - if(!isTransactionalOutboxModuleLoaded) + if(!isTransactionalOutboxModuleLoaded && options.InMemoryOutboxEnabled) { cfg.UseInMemoryOutbox(); } diff --git a/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/RabbitMqMessagingOptions.cs b/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/RabbitMqMessagingOptions.cs index 52c0891a..ac07eee7 100644 --- a/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/RabbitMqMessagingOptions.cs +++ b/src/Fluxera.Extensions.Hosting.Modules.Messaging.RabbitMQ/RabbitMqMessagingOptions.cs @@ -17,6 +17,14 @@ public RabbitMqMessagingOptions() this.ConnectionStrings = new ConnectionStrings(); } + /// + /// Gets or sets a value indicating whether the in-memory outbox is enabled. + /// + /// + /// true if the in-memory outbox is enabled; otherwise, false. + /// + public bool InMemoryOutboxEnabled { get; set; } = true; + /// /// Gets or sets the name of the connection string to use. ///