Skip to content

Commit

Permalink
Add snippets for SqlT v8 (#6286)
Browse files Browse the repository at this point in the history
* Add snippets for SqlT v8

* Regenerate scripts

* Get shared tests to work

* Remove unused snippets

* Tweaks

---------

Co-authored-by: Brandon Ording <[email protected]>
  • Loading branch information
andreasohlund and bording authored Nov 1, 2023
1 parent 5bc0bae commit 35b9aba
Show file tree
Hide file tree
Showing 45 changed files with 836 additions and 34 deletions.
6 changes: 6 additions & 0 deletions Snippets/SqlTransport/SqlTransport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlTransport_7", "SqlTransp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlTransport_6.3", "SqlTransport_6.3\SqlTransport_6.3.csproj", "{3AD9DC42-357B-4249-91AC-9AAAD01286CA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlTransport_8", "SqlTransport_8\SqlTransport_8.csproj", "{28475FD9-E115-415E-8C77-A873E3B0E536}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -44,6 +46,10 @@ Global
{3AD9DC42-357B-4249-91AC-9AAAD01286CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AD9DC42-357B-4249-91AC-9AAAD01286CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AD9DC42-357B-4249-91AC-9AAAD01286CA}.Release|Any CPU.Build.0 = Release|Any CPU
{28475FD9-E115-415E-8C77-A873E3B0E536}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28475FD9-E115-415E-8C77-A873E3B0E536}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28475FD9-E115-415E-8C77-A873E3B0E536}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28475FD9-E115-415E-8C77-A873E3B0E536}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<RootNamespace>SqlTransport_6._1</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="6.1.*" />
<PackageReference Include="NUnit" Version="3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<RootNamespace>SqlTransport_6._2</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="6.2.*" />
<PackageReference Include="NUnit" Version="3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>
</Project>
10 changes: 3 additions & 7 deletions Snippets/SqlTransport/SqlTransport_6.3/SqlTransport_6.3.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<RootNamespace>SqlTransport_6._3</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="6.3.*" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="NUnit" Version="3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE TABLE {0} (

CREATE NONCLUSTERED INDEX Index_RowVersion ON {0}
(
RowVersion
[RowVersion] ASC
)

CREATE NONCLUSTERED INDEX Index_Expires ON {0}
Expand Down
4 changes: 2 additions & 2 deletions Snippets/SqlTransport/SqlTransport_6/SqlTransport_6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ItemGroup>
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="6.0.*" />
<PackageReference Include="NUnit" Version="3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ OUTPUT
INTO {1};

SELECT TOP 1 GETUTCDATE() as UtcNow, Due as NextDue
FROM {0}
ORDER BY Due";
FROM {0} WITH (READPAST)
ORDER BY Due
endcode
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ WITH message AS (
DELETE FROM message
OUTPUT
deleted.Id,
deleted.CorrelationId,
deleted.ReplyToAddress,
CASE WHEN deleted.Expires IS NULL
THEN 0
ELSE CASE WHEN deleted.Expires > GETUTCDATE()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ SET NOCOUNT ON;

INSERT INTO {0} (
Id,
CorrelationId,
ReplyToAddress,
Recoverable,
Expires,
Headers,
Body)
VALUES (
@Id,
@CorrelationId,
@ReplyToAddress,
1,
CASE WHEN @TimeToBeReceivedMs IS NOT NULL
THEN DATEADD(ms, @TimeToBeReceivedMs, GETUTCDATE()) END,
@Headers,
Expand Down
4 changes: 2 additions & 2 deletions Snippets/SqlTransport/SqlTransport_7/SqlTransport_7.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ItemGroup>
<PackageReference Include="NServiceBus.Transport.SqlServer" Version="7.*" />
<PackageReference Include="NUnit" Version="3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="3.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/ConfigurationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using NServiceBus;

class ConfigurationSettings
{
ConfigurationSettings(EndpointConfiguration endpointConfiguration)
{
#region sqlserver-TimeToWaitBeforeTriggeringCircuitBreaker

var transport = new SqlServerTransport("connectionString")
{
TimeToWaitBeforeTriggeringCircuitBreaker = TimeSpan.FromMinutes(3)
};

#endregion
}
}
9 changes: 9 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/ConnectionStrings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--startcode sqlserver-connection-string-xml-->
<configuration>
<connectionStrings>
<add name="NServiceBus/Transport"
connectionString="Data Source=instance; Initial Catalog=db; Integrated Security=True;Max Pool Size=80"/>
</connectionStrings>
</configuration>
<!--endcode-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.Data.SqlClient;
using System.Threading.Tasks;
using System.Transactions;
using NServiceBus;

class CustomConnectionAndTransaction
{
async Task Usage(IMessageSession session, string connectionString, string commandText)
{
#region UseCustomSqlConnectionAndTransaction

using (var connection = new SqlConnection(connectionString))
{
connection.Open();

using (var transaction = connection.BeginTransaction())
{
var sqlCommand = new SqlCommand(commandText, connection, transaction);

//Execute SQL statement
sqlCommand.ExecuteNonQuery();

//Send a message
var sendOptions = new SendOptions();
sendOptions.UseCustomSqlTransaction(transaction);
await session.Send(new Message(), sendOptions);

//Publish a message
var publishOptions = new PublishOptions();
publishOptions.UseCustomSqlTransaction(transaction);
await session.Publish(new Event(), publishOptions);

transaction.Commit();
}
}

#endregion

#region UseCustomSqlConnection

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew,
TransactionScopeAsyncFlowOption.Enabled))
{
using (var connection = new SqlConnection(connectionString))
{
connection.Open();

var sqlCommand = new SqlCommand(commandText, connection);

//Execute SQL statement
sqlCommand.ExecuteNonQuery();

//Send a message
var sendOptions = new SendOptions();
sendOptions.UseCustomSqlConnection(connection);
await session.Send(new Message(), sendOptions);

//Publish a message
var publishOptions = new PublishOptions();
publishOptions.UseCustomSqlConnection(connection);
await session.Publish(new Event(), publishOptions);
}

scope.Complete();
}

#endregion
}

class Message { };
class Event { };
}
16 changes: 16 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/DefaultCatalog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using NServiceBus;

class DefaultCatalog
{
void OverwriteDefaultCatalog()
{
#region sqlserver-default-catalog

var transport = new SqlServerTransport("connectionString")
{
DefaultCatalog = "mycatalog"
};

#endregion
}
}
35 changes: 35 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/DelayConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using NServiceBus;

class DelayConfig
{
void ConfigurePeekDelay(EndpointConfiguration endpointConfiguration)
{
#region sqlserver-queue-peeker-config-delay

var transport = new SqlServerTransport("connectionString")
{
QueuePeeker =
{
Delay = TimeSpan.FromSeconds(5)
}
};

#endregion
}

void ConfigurePeekBatchSize(EndpointConfiguration endpointConfiguration)
{
#region sqlserver-queue-peeker-config-batch-size

var transport = new SqlServerTransport("connectionString")
{
QueuePeeker =
{
MaxRecordsToPeek = 50
}
};

#endregion
}
}
22 changes: 22 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/DelayedDelivery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using NServiceBus;

class DelayedDelivery
{
void Configure(EndpointConfiguration endpointConfiguration)
{
var transport = new SqlServerTransport("");

#region DelayedDeliveryTableSuffix

transport.DelayedDelivery.TableSuffix = "Delayed";

#endregion

#region DelayedDeliveryBatchSize

transport.DelayedDelivery.BatchSize = 100;

#endregion
}
}
20 changes: 20 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/DiscardMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NServiceBus;

class DiscardMessages
{
void Configure(EndpointConfiguration endpointConfiguration)
{
#region purge-expired-on-startup

var transport = new SqlServerTransport("connectionString")
{
ExpiredMessagesPurger =
{
PurgeOnStartup = true,
PurgeBatchSize = 5000
}
};

#endregion
}
}
12 changes: 12 additions & 0 deletions Snippets/SqlTransport/SqlTransport_8/ExpiredIndex.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--startcode sql-ExpiresIndex
create nonclustered index [Index_Expires]
on [schema].[queuename]
(
[Expires] asc
)
include
(
[Id],
[RowVersion]
)
--endcode
Loading

0 comments on commit 35b9aba

Please sign in to comment.