Skip to content

Commit 5b3cf7e

Browse files
author
Christian
committed
disable outbox table creation
a
1 parent dc57bab commit 5b3cf7e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/NServiceBus.NHibernate.TransactionalSession/NHibernateTransactionalSessionExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static PersistenceExtensions<NHibernatePersistence> EnableTransactionalSe
4848
//By default, the endpoint name used is automatically managed and set to the originating endpoint's name unless overridden by setting a value to NHibernateOutbox.ProcessorEndpointKey
4949
settings.Set(NHibernateOutbox.ProcessorEndpointKey, transactionalSessionOptions.ProcessorAddress);
5050

51+
// If a remote processor is configured, this endpoint should not create the outbox tables.
52+
settings.Set(NHibernateOutbox.DisableOutboxTableCreationSettingKey, true);
53+
5154
return persistenceExtensions;
5255
}
5356

src/NServiceBus.NHibernate/Outbox/NHibernateOutbox.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class NHibernateOutbox : Feature
2525
internal const string OutboxTransactionIsolationLevelSettingsKey = "NServiceBus.NHibernate.OutboxTransactionIsolationLevel";
2626
internal const string OutboxTransactionScopeModeIsolationLevelSettingsKey = "NServiceBus.NHibernate.OutboxTransactionScopeModeIsolationLevel";
2727
internal const string ProcessorEndpointKey = "NHibernate.TransactionalSession.ProcessorEndpoint";
28+
internal const string DisableOutboxTableCreationSettingKey = "NServiceBus.NHibernate.DisableOutboxTableCreation";
2829
/// <summary>
2930
/// Creates a new instance of the feature
3031
/// </summary>
@@ -67,7 +68,9 @@ protected override void Setup(FeatureConfigurationContext context)
6768
throw new Exception("Custom outbox table name and custom outbox record type cannot be specified at the same time.");
6869
}
6970

70-
ApplyMappings(config.Configuration, actualOutboxRecordType, outboxTableName, outboxSchemaName);
71+
var disableOutboxTableCreation = context.Settings.GetOrDefault<bool>(DisableOutboxTableCreationSettingKey);
72+
73+
ApplyMappings(config.Configuration, actualOutboxRecordType, outboxTableName, outboxSchemaName, disableOutboxTableCreation);
7174

7275
var persisterFactory = context.Settings.Get<IOutboxPersisterFactory>();
7376
context.Services.AddSingleton<IOutboxStorage>(sp =>
@@ -87,11 +90,12 @@ protected override void Setup(FeatureConfigurationContext context)
8790
OutboxCleanupCriticalErrorTriggerTime = outboxCleanupCriticalErrorTriggerTime,
8891
RecordType = actualOutboxRecordType.FullName,
8992
CustomOutboxTableName = outboxTableName,
90-
CustomOutboxSchemaName = outboxSchemaName
93+
CustomOutboxSchemaName = outboxSchemaName,
94+
OutboxTableCreationDisabled = disableOutboxTableCreation
9195
});
9296
}
9397

94-
static void ApplyMappings(Configuration config, Type outboxRecordType, string customOutboxTableName, string customOutboxSchemaName)
98+
static void ApplyMappings(Configuration config, Type outboxRecordType, string customOutboxTableName, string customOutboxSchemaName, bool disableSchemaExport = false)
9599
{
96100
var mapper = new ModelMapper();
97101
mapper.BeforeMapClass += (inspector, type, customizer) =>
@@ -104,6 +108,12 @@ static void ApplyMappings(Configuration config, Type outboxRecordType, string cu
104108
{
105109
customizer.Schema(customOutboxSchemaName);
106110
}
111+
112+
// Set schema-export attribute to none if schema export is disabled
113+
if (disableSchemaExport)
114+
{
115+
customizer.SchemaAction(SchemaAction.None);
116+
}
107117
};
108118
mapper.AddMapping(outboxRecordType);
109119
config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

0 commit comments

Comments
 (0)