Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Mar 14, 2024
1 parent 4a65d93 commit 3bdc72d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.2" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="9.0.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.2" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NServiceBus.AcceptanceTests.Sources" Version="9.0.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.2" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NServiceBus.PersistenceTests.Sources" Version="9.0.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.2" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NServiceBus" Version="9.0.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.2" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="9.0.0" />
<PackageReference Include="NServiceBus.TransactionalSession" Version="3.0.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.19.2" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="NServiceBus" Version="9.0.0" />
<PackageReference Include="NServiceBus.TransactionalSession" Version="3.0.0" />
<PackageReference Include="Particular.Approvals" Version="1.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="[2.19.2, 3.0.0)" />
<PackageReference Include="MongoDB.Driver" Version="[2.24.0, 3.0.0)" />
<PackageReference Include="NServiceBus" Version="[9.0.0, 10.0.0)" />
<PackageReference Include="Particular.Packaging" Version="4.1.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,38 @@ protected override void Setup(FeatureConfigurationContext context)
{
var database = client.GetDatabase(databaseName);

// perform a query to the server to make sure cluster details are loaded so we can check them later
// perform a query to the server to make sure cluster details are loaded
database.ListCollectionNames();
}
catch (ArgumentException ex)
{
throw new Exception($"The persistence database name '{databaseName}' is invalid. Configure a valid database name by calling 'EndpointConfiguration.UsePersistence<{nameof(MongoPersistence)}>().DatabaseName(databaseName)'.", ex);
}

try
{
using (var session = client.StartSession())
using var session = client.StartSession();

if (useTransactions)
{
if (useTransactions)
{
var clusterType = client.Cluster.Description.Type;
var clusterType = client.Cluster.Description.Type;

//HINT: cluster configuration check is needed as the built-in checks, executed during "StartTransaction() call,
// do not detect if the cluster configuration is a supported one. Only the version ranges are validated.
// Without this check, exceptions will be thrown during message processing.
if (clusterType is not ClusterType.ReplicaSet and not ClusterType.Sharded)
{
throw new Exception($"Cluster type in use is {clusterType}, transactions are only supported on replica sets or sharded clusters. Disable support for transactions by calling 'EndpointConfiguration.UsePersistence<{nameof(MongoPersistence)}>().UseTransactions(false)'.");
}
//HINT: cluster configuration check is needed as the built-in checks, executed during "StartTransaction() call,
// do not detect if the cluster configuration is a supported one. Only the version ranges are validated.
// Without this check, exceptions will be thrown during message processing.
if (clusterType is not ClusterType.ReplicaSet and not ClusterType.Sharded)
{
throw new Exception($"The cluster type in use is {clusterType}, but transactions are only supported on replica sets or sharded clusters. Disable support for transactions by calling 'EndpointConfiguration.UsePersistence<{nameof(MongoPersistence)}>().UseTransactions(false)'.");
}

try
{
session.StartTransaction();
session.AbortTransaction();
}
catch (NotSupportedException ex)
{
throw new Exception($"Transactions are not supported by the MongoDB server. Disable support for transactions by calling 'EndpointConfiguration.UsePersistence<{nameof(MongoPersistence)}>().UseTransactions(false)'.", ex);
}
try
{
session.StartTransaction();
session.AbortTransaction();
}
catch (NotSupportedException ex)
{
throw new Exception($"Transactions are not supported by the MongoDB server. Disable support for transactions by calling 'EndpointConfiguration.UsePersistence<{nameof(MongoPersistence)}>().UseTransactions(false)'.", ex);
}
}
}
catch (ArgumentException ex)
{
throw new Exception($"The persistence database name '{databaseName}' is invalid. Configure a valid database name by calling 'EndpointConfiguration.UsePersistence<{nameof(MongoPersistence)}>().DatabaseName(databaseName)'.", ex);
}
catch (NotSupportedException ex)
{
throw new Exception("Sessions are not supported by the MongoDB server. The NServiceBus.Storage.MongoDB persistence requires MongoDB server version 3.6 or greater.", ex);
Expand Down

0 comments on commit 3bdc72d

Please sign in to comment.