Skip to content

Commit

Permalink
Add transaction mode validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Mar 30, 2023
1 parent 6fa010a commit 9f0f249
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/AcceptanceTesting/AcceptanceTesting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus" Version="7.4.0-*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.0.0-*" />
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="7.4.0-*" />
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="7.7.*" />
<PackageReference Include="NUnit" Version="3.12.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public TestTransportInfrastructure(SettingsHolder settings)
typeof(DoNotDeliverBefore)
};

public override TransportTransactionMode TransactionMode => TransportTransactionMode.SendsAtomicWithReceive;
public override TransportTransactionMode TransactionMode => TransportTransactionMode.ReceiveOnly;

public override OutboundRoutingPolicy OutboundRoutingPolicy { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" PrivateAssets="All" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" PrivateAssets="All" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NServiceBus.Metrics.ServiceControl" Version="3.0.2" />
<PackageReference Include="NServiceBus.SqlServer" Version="4.1.*" />
<PackageReference Include="NServiceBus" Version="[7.4.0, 8.0.0)" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.0.0-*" />
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="7.4.0-*" />
<PackageReference Include="NServiceBus.Bridge.Connector" Version="2.0.0-*" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="NServiceBus.Azure.Transports.WindowsAzureServiceBus" Version="9.1.0-*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AcceptanceTesting\AcceptanceTesting.csproj" />
<ProjectReference Include="..\NServiceBus.Router.Connector\NServiceBus.Router.Connector.csproj" />
<ProjectReference Include="..\NServiceBus.Router.SqlServer\NServiceBus.Router.SqlServer.csproj" />
<ProjectReference Include="..\NServiceBus.Router\NServiceBus.Router.csproj" />
<ProjectReference Include="..\NServiceBus.Router.Migrator\NServiceBus.Router.Migrator.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NServiceBus.Metrics.ServiceControl" Version="3.0.2" />
<PackageReference Include="NServiceBus.SqlServer" Version="4.1.*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.0.0-*" />
<PackageReference Include="NServiceBus.Bridge.Connector" Version="2.0.0-*" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="NServiceBus.Azure.Transports.WindowsAzureServiceBus" Version="9.1.0-*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AcceptanceTesting\AcceptanceTesting.csproj" />
<ProjectReference Include="..\NServiceBus.Router.Connector\NServiceBus.Router.Connector.csproj" />
<ProjectReference Include="..\NServiceBus.Router.SqlServer\NServiceBus.Router.SqlServer.csproj" />
<ProjectReference Include="..\NServiceBus.Router\NServiceBus.Router.csproj" />
<ProjectReference Include="..\NServiceBus.Router.Migrator\NServiceBus.Router.Migrator.csproj" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions src/NServiceBus.Router/ThrottlingRawEndpointConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,32 @@ Task onCriticalError(ICriticalErrorContext context)
throttledConfig.LimitMessageProcessingConcurrencyTo(1);
return throttledConfig;
}

public async Task<IStartableRawEndpoint> Create()
{
startable = await RawEndpoint.Create(config);
ValidateTransactionMode(startable);
config = null;
return this;
}

static void ValidateTransactionMode(IStartableRawEndpoint startableRawEndpoint)
{
var infra = startableRawEndpoint.Settings.Get<TransportInfrastructure>();

if (startableRawEndpoint.Settings.TryGet<TransportTransactionMode>(out var selectedMode))
{
if (selectedMode == TransportTransactionMode.SendsAtomicWithReceive)
{
throw new Exception("Router cannot operate in SendsAtomicWithReceive transaction mode. Please select other transaction mode.");
}
}
else if (infra.TransactionMode == TransportTransactionMode.SendsAtomicWithReceive)
{
throw new Exception($"{infra.GetType()} defaults to SendsAtomicWithReceive transaction mode. Router cannot operate in that mode. Customize the transport configuration to use SendsAtomicWithReceive mode.");
}
}

async Task<IReceivingRawEndpoint> IStartableRawEndpoint.Start()
{
endpoint = await startable.Start().ConfigureAwait(false);
Expand Down

0 comments on commit 9f0f249

Please sign in to comment.