Skip to content

Commit c664a58

Browse files
andreasohlundcquirosjpoornimanayar
authored
Add new configuration API for Transactional Session v3.3.0 (#1754)
* Add new tx session config API * Disable outbox cleanup if remote processor is set * Approve API * Approve * Sort internals visible to * Add acceptance test * Make processor use send only outbox * Make persistence available via settings * Avoid using test keys * Add test for old client * Revert * Fix capturing logic * Remove uneeded behavior * Use new service provider capturing approach * Update src/NServiceBus.Persistence.Sql.TransactionalSession/SqlPersistenceTransactionalSessionExtensions.cs * WIP * Make the processor endpoint own the outbox storage with transactional session * Remove the outbox table creation * remove a line of code * Creating outbox table moved to processor * Make passing endpoint name explicit * Do not create outbox table when processor endpoint is defined * update to latest beta of tx session * Update to 3.3.0 --------- Co-authored-by: Christian <christian.quiros@particular.net> Co-authored-by: Poornima Nayar <poornima.nayar@particular.net>
1 parent c6886ff commit c664a58

30 files changed

+332
-143
lines changed

src/NServiceBus.Persistence.Sql.TransactionalSession/NServiceBus.Persistence.Sql.TransactionalSession.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="NServiceBus.TransactionalSession" Version="3.2.0" />
17+
<PackageReference Include="NServiceBus.TransactionalSession" Version="3.3.0" />
1818
<PackageReference Include="Particular.Packaging" Version="4.2.2" PrivateAssets="All" />
1919
</ItemGroup>
2020

src/NServiceBus.Persistence.Sql.TransactionalSession/SqlPersistenceTransactionalSessionExtensions.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NServiceBus.TransactionalSession
22
{
3+
using System;
34
using Configuration.AdvancedExtensibility;
45
using Features;
56

@@ -12,9 +13,34 @@ public static class SqlPersistenceTransactionalSessionExtensions
1213
/// Enables transactional session for this endpoint.
1314
/// </summary>
1415
public static PersistenceExtensions<SqlPersistence> EnableTransactionalSession(
15-
this PersistenceExtensions<SqlPersistence> persistenceExtensions)
16+
this PersistenceExtensions<SqlPersistence> persistenceExtensions) =>
17+
EnableTransactionalSession(persistenceExtensions, new TransactionalSessionOptions());
18+
19+
/// <summary>
20+
/// Enables the transactional session for this endpoint using the specified TransactionalSessionOptions.
21+
/// </summary>
22+
public static PersistenceExtensions<SqlPersistence> EnableTransactionalSession(this PersistenceExtensions<SqlPersistence> persistenceExtensions,
23+
TransactionalSessionOptions transactionalSessionOptions)
1624
{
17-
persistenceExtensions.GetSettings().EnableFeatureByDefault<SqlPersistenceTransactionalSession>();
25+
ArgumentNullException.ThrowIfNull(persistenceExtensions);
26+
ArgumentNullException.ThrowIfNull(transactionalSessionOptions);
27+
28+
var settings = persistenceExtensions.GetSettings();
29+
30+
settings.Set(transactionalSessionOptions);
31+
settings.EnableFeatureByDefault<SqlPersistenceTransactionalSession>();
32+
33+
if (!string.IsNullOrEmpty(transactionalSessionOptions.ProcessorEndpoint))
34+
{
35+
settings.Set(SqlOutboxFeature.ProcessorEndpointKey, transactionalSessionOptions.ProcessorEndpoint);
36+
37+
settings.GetOrCreate<InstallerSettings>()
38+
.DoNotCreateOutboxTable = true;
39+
40+
// remote processor configured so turn off the outbox cleanup on this instance
41+
settings.Set(SqlOutboxFeature.DisableCleanup, true);
42+
}
43+
1844
return persistenceExtensions;
1945
}
2046
}

src/SqlPersistence.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"AcceptanceTestHelper, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
22
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"MsSqlMicrosoftDataClientSqlTransportAcceptanceTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
3+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"NServiceBus.Persistence.Sql.TransactionalSession, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")]
34
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"OracleAcceptanceTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
45
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"PostgreSqlTransportAcceptanceTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
56
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"SqlPersistence.PersistenceTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]

src/SqlPersistence/Config/SqlPersistenceConfig_TablePrefix.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ public static void TablePrefix(this PersistenceExtensions<SqlPersistence> config
1818
.Set("SqlPersistence.TablePrefix", tablePrefix);
1919
}
2020

21-
internal static string GetTablePrefix(this IReadOnlySettings settings)
21+
internal static string GetTablePrefix(this IReadOnlySettings settings, string endpointName)
2222
{
23-
if (settings.TryGet("SqlPersistence.TablePrefix", out string tablePrefix))
23+
if (settings.TryGet("SqlPersistence.TablePrefix", out string overriddenTablePrefix))
2424
{
25-
return tablePrefix;
25+
return overriddenTablePrefix;
2626
}
27-
var endpointName = settings.EndpointName();
28-
var clean = TableNameCleaner.Clean(endpointName);
29-
return $"{clean}_";
30-
}
3127

28+
return $"{TableNameCleaner.Clean(endpointName)}_";
29+
}
3230
}
3331
}

src/SqlPersistence/InstallerFeature.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
class InstallerFeature : Feature
55
{
6-
public InstallerFeature()
7-
{
8-
Defaults(s => s.SetDefault(new InstallerSettings()));
9-
}
6+
public InstallerFeature() => Defaults(s => s.SetDefault(new InstallerSettings()));
107

118
protected override void Setup(FeatureConfigurationContext context)
129
{
@@ -19,7 +16,7 @@ protected override void Setup(FeatureConfigurationContext context)
1916
settings.ConnectionBuilder = storageType => context.Settings.GetConnectionBuilder(storageType).BuildNonContextual();
2017
settings.Dialect = context.Settings.GetSqlDialect();
2118
settings.ScriptDirectory = ScriptLocation.FindScriptDirectory(context.Settings);
22-
settings.TablePrefix = context.Settings.GetTablePrefix();
19+
settings.TablePrefix = context.Settings.GetTablePrefix(context.Settings.EndpointName());
2320
settings.IsMultiTenant = context.Settings.EndpointIsMultiTenant();
2421

2522
settings.Dialect.ValidateTablePrefix(settings.TablePrefix);

src/SqlPersistence/InstallerSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class InstallerSettings
1010
public string ScriptDirectory { get; set; }
1111
public string TablePrefix { get; set; }
1212
public bool IsMultiTenant { get; set; }
13+
public bool DoNotCreateOutboxTable { get; set; }
1314
}

src/SqlPersistence/Outbox/SqlOutboxFeature.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ protected override void Setup(FeatureConfigurationContext context)
2020
{
2121
var settings = context.Settings;
2222
var connectionManager = settings.GetConnectionBuilder<StorageType.Outbox>();
23-
var tablePrefix = settings.GetTablePrefix();
23+
var endpointName = settings.GetOrDefault<string>(ProcessorEndpointKey) ?? settings.EndpointName();
24+
var tablePrefix = settings.GetTablePrefix(endpointName);
2425
var sqlDialect = settings.GetSqlDialect();
2526

2627
var pessimisticMode = context.Settings.GetOrDefault<bool>(ConcurrencyMode);
@@ -94,4 +95,5 @@ ISqlOutboxTransaction transactionFactory()
9495
internal const string AdoTransactionIsolationLevel = "Persistence.Sql.Outbox.AdoTransactionIsolationLevel";
9596
internal const string TransactionScopeIsolationLevel = "Persistence.Sql.Outbox.TransactionScopeIsolationLevel";
9697
internal const string TransactionScopeTimeout = "Persistence.Sql.Outbox.TransactionScopeTimeout";
98+
internal const string ProcessorEndpointKey = "Persistence.Sql.TransactionalSession.ProcessorEndpoint";
9799
}

src/SqlPersistence/Saga/SqlSagaFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static SagaInfoCache BuildSagaInfoCache(SqlDialect sqlDialect, IReadOnlySettings
5656
var nameFilter = SagaSettings.GetNameFilter(settings);
5757
nameFilter ??= sagaName => sagaName;
5858
var versionDeserializeBuilder = SagaSettings.GetVersionSettings(settings);
59-
var tablePrefix = settings.GetTablePrefix();
59+
var tablePrefix = settings.GetTablePrefix(settings.EndpointName());
6060
return new SagaInfoCache(
6161
versionSpecificSettings: versionDeserializeBuilder,
6262
jsonSerializer: jsonSerializer,

src/SqlPersistence/SqlPersistence.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<ItemGroup>
4040
<InternalsVisibleTo Include="AcceptanceTestHelper" Key="$(NServiceBusTestsKey)" />
4141
<InternalsVisibleTo Include="MsSqlMicrosoftDataClientSqlTransportAcceptanceTests" Key="$(NServiceBusTestsKey)" />
42+
<InternalsVisibleTo Include="NServiceBus.Persistence.Sql.TransactionalSession" Key="$(NServiceBusKey)" />
4243
<InternalsVisibleTo Include="OracleAcceptanceTests" Key="$(NServiceBusTestsKey)" />
4344
<InternalsVisibleTo Include="PostgreSqlTransportAcceptanceTests" Key="$(NServiceBusTestsKey)" />
4445
<InternalsVisibleTo Include="SqlPersistence.PersistenceTests" Key="$(NServiceBusTestsKey)" />

src/SqlPersistence/NeedToInstallSomething.cs renamed to src/SqlPersistence/SqlPersistenceInstaller.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@
55
using NServiceBus.Persistence.Sql;
66
using NServiceBus.Settings;
77

8-
class SqlPersistenceInstaller : INeedToInstallSomething
8+
class SqlPersistenceInstaller(IReadOnlySettings settings) : INeedToInstallSomething
99
{
10-
readonly InstallerSettings installerSettings;
11-
readonly IReadOnlySettings settings;
12-
13-
public SqlPersistenceInstaller(IReadOnlySettings settings)
14-
{
15-
this.settings = settings;
16-
installerSettings = settings.GetOrDefault<InstallerSettings>();
17-
}
18-
1910
public async Task Install(string identity, CancellationToken cancellationToken = default)
2011
{
2112
if (installerSettings == null || installerSettings.Disabled)
@@ -28,10 +19,12 @@ await ScriptRunner.Install(
2819
tablePrefix: installerSettings.TablePrefix,
2920
connectionBuilder: installerSettings.ConnectionBuilder,
3021
scriptDirectory: installerSettings.ScriptDirectory,
31-
shouldInstallOutbox: !installerSettings.IsMultiTenant && settings.IsFeatureActive(typeof(SqlOutboxFeature)),
22+
shouldInstallOutbox: !installerSettings.DoNotCreateOutboxTable && !installerSettings.IsMultiTenant && settings.IsFeatureActive(typeof(SqlOutboxFeature)),
3223
shouldInstallSagas: !installerSettings.IsMultiTenant && settings.IsFeatureActive(typeof(SqlSagaFeature)),
3324
shouldInstallSubscriptions: settings.IsFeatureActive(typeof(SqlSubscriptionFeature)),
3425
cancellationToken: cancellationToken)
3526
.ConfigureAwait(false);
3627
}
37-
}
28+
29+
readonly InstallerSettings installerSettings = settings.GetOrDefault<InstallerSettings>();
30+
}

0 commit comments

Comments
 (0)