From 3bdc72d9b59868bf3953522597602e279539605d Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 14 Mar 2024 11:05:35 -0400 Subject: [PATCH] Tweaks --- ...Bus.Storage.MongoDB.AcceptanceTests.csproj | 2 +- ...torage.MongoDB.NoTx.AcceptanceTests.csproj | 2 +- ...us.Storage.MongoDB.PersistenceTests.csproj | 2 +- .../NServiceBus.Storage.MongoDB.Tests.csproj | 2 +- ...ransactionalSession.AcceptanceTests.csproj | 2 +- ....MongoDB.TransactionalSession.Tests.csproj | 2 +- .../NServiceBus.Storage.MongoDB.csproj | 4 +- .../SynchronizedStorage.cs | 52 +++++++++---------- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/NServiceBus.Storage.MongoDB.AcceptanceTests/NServiceBus.Storage.MongoDB.AcceptanceTests.csproj b/src/NServiceBus.Storage.MongoDB.AcceptanceTests/NServiceBus.Storage.MongoDB.AcceptanceTests.csproj index 704d3fbf..adf9e957 100644 --- a/src/NServiceBus.Storage.MongoDB.AcceptanceTests/NServiceBus.Storage.MongoDB.AcceptanceTests.csproj +++ b/src/NServiceBus.Storage.MongoDB.AcceptanceTests/NServiceBus.Storage.MongoDB.AcceptanceTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests.csproj b/src/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests.csproj index 704d3fbf..adf9e957 100644 --- a/src/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests.csproj +++ b/src/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests/NServiceBus.Storage.MongoDB.NoTx.AcceptanceTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/NServiceBus.Storage.MongoDB.PersistenceTests/NServiceBus.Storage.MongoDB.PersistenceTests.csproj b/src/NServiceBus.Storage.MongoDB.PersistenceTests/NServiceBus.Storage.MongoDB.PersistenceTests.csproj index ad39fe0d..5ac9f96f 100644 --- a/src/NServiceBus.Storage.MongoDB.PersistenceTests/NServiceBus.Storage.MongoDB.PersistenceTests.csproj +++ b/src/NServiceBus.Storage.MongoDB.PersistenceTests/NServiceBus.Storage.MongoDB.PersistenceTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/NServiceBus.Storage.MongoDB.Tests/NServiceBus.Storage.MongoDB.Tests.csproj b/src/NServiceBus.Storage.MongoDB.Tests/NServiceBus.Storage.MongoDB.Tests.csproj index ad4fc51e..924a2439 100644 --- a/src/NServiceBus.Storage.MongoDB.Tests/NServiceBus.Storage.MongoDB.Tests.csproj +++ b/src/NServiceBus.Storage.MongoDB.Tests/NServiceBus.Storage.MongoDB.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests.csproj b/src/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests.csproj index b9cbcced..7414c147 100644 --- a/src/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests.csproj +++ b/src/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests/NServiceBus.Storage.MongoDB.TransactionalSession.AcceptanceTests.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/NServiceBus.Storage.MongoDB.TransactionalSession.Tests/NServiceBus.Storage.MongoDB.TransactionalSession.Tests.csproj b/src/NServiceBus.Storage.MongoDB.TransactionalSession.Tests/NServiceBus.Storage.MongoDB.TransactionalSession.Tests.csproj index 0aa48a0f..91d45c96 100644 --- a/src/NServiceBus.Storage.MongoDB.TransactionalSession.Tests/NServiceBus.Storage.MongoDB.TransactionalSession.Tests.csproj +++ b/src/NServiceBus.Storage.MongoDB.TransactionalSession.Tests/NServiceBus.Storage.MongoDB.TransactionalSession.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/NServiceBus.Storage.MongoDB/NServiceBus.Storage.MongoDB.csproj b/src/NServiceBus.Storage.MongoDB/NServiceBus.Storage.MongoDB.csproj index 61bd5974..1c5124d1 100644 --- a/src/NServiceBus.Storage.MongoDB/NServiceBus.Storage.MongoDB.csproj +++ b/src/NServiceBus.Storage.MongoDB/NServiceBus.Storage.MongoDB.csproj @@ -1,11 +1,11 @@ - + net8.0 - + diff --git a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorage.cs b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorage.cs index 6df03404..5a8e26c9 100644 --- a/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorage.cs +++ b/src/NServiceBus.Storage.MongoDB/SynchronizedStorage/SynchronizedStorage.cs @@ -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);