Skip to content

Commit 8a9bbcb

Browse files
DynamoDB v3: Samples, Snippets and upgrade guide (#7178)
* Samples, Snippets and upgrade guide * RTM * Move command creation * Bump review date --------- Co-authored-by: Daniel Marbach <[email protected]>
1 parent 36de5cf commit 8a9bbcb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1250
-14
lines changed

Snippets/DynamoDB/DynamoDB.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamoDB_2", "DynamoDB_2\Dy
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamoDB_2.1", "DynamoDB_2.1\DynamoDB_2.1.csproj", "{67406601-D317-43DE-98D1-981CDFDD96DD}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamoDB_3", "DynamoDB_3\DynamoDB_3.csproj", "{CEAE5139-70EF-463A-A649-6E5D1D87715B}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{67406601-D317-43DE-98D1-981CDFDD96DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{67406601-D317-43DE-98D1-981CDFDD96DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{67406601-D317-43DE-98D1-981CDFDD96DD}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{CEAE5139-70EF-463A-A649-6E5D1D87715B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{CEAE5139-70EF-463A-A649-6E5D1D87715B}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{CEAE5139-70EF-463A-A649-6E5D1D87715B}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{CEAE5139-70EF-463A-A649-6E5D1D87715B}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Amazon.DynamoDBv2;
2+
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
using NServiceBus;
6+
using NServiceBus.Persistence.DynamoDB;
7+
8+
#region DynamoDBCustomClientProvider
9+
10+
class CustomDynamoClientProvider
11+
: IDynamoClientProvider
12+
{
13+
// get fully configured via DI
14+
public CustomDynamoClientProvider(IAmazonDynamoDB dynamoClient)
15+
{
16+
Client = dynamoClient;
17+
}
18+
public IAmazonDynamoDB Client { get; }
19+
}
20+
#endregion
21+
22+
class DynamoDBCustomClientProviderRegistration
23+
{
24+
public DynamoDBCustomClientProviderRegistration(EndpointConfiguration endpointConfiguration)
25+
{
26+
#region DynamoDBCustomClientProviderRegistration
27+
28+
endpointConfiguration.RegisterComponents(c => c.AddTransient<IDynamoClientProvider, CustomDynamoClientProvider>());
29+
30+
#endregion
31+
}
32+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Amazon.DynamoDBv2;
2+
using Amazon.Runtime;
3+
4+
using NServiceBus;
5+
6+
namespace DynamoDB_3;
7+
8+
public class Customization
9+
{
10+
void SharedTableConfig(PersistenceExtensions<DynamoPersistence> persistence)
11+
{
12+
#region DynamoDBTableCustomizationShared
13+
14+
persistence.UseSharedTable(new TableConfiguration
15+
{
16+
TableName = "MyTable",
17+
PartitionKeyName = "MyPartitionKey",
18+
SortKeyName = "MySortKey"
19+
});
20+
21+
#endregion
22+
}
23+
24+
void DisableTableCreation(PersistenceExtensions<DynamoPersistence> persistence)
25+
{
26+
#region DynamoDBDisableTableCreation
27+
28+
persistence.DisableTablesCreation();
29+
30+
#endregion
31+
}
32+
33+
void ThrottlingConfig(PersistenceExtensions<DynamoPersistence> persistence)
34+
{
35+
#region DynamoDBConfigureThrottlingWithClientConfig
36+
37+
var dynamoDbClient = new AmazonDynamoDBClient(
38+
new AmazonDynamoDBConfig
39+
{
40+
Timeout = TimeSpan.FromSeconds(10),
41+
RetryMode = RequestRetryMode.Adaptive,
42+
MaxErrorRetry = 3
43+
});
44+
persistence.DynamoClient(dynamoDbClient);
45+
46+
#endregion
47+
}
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="NServiceBus.Persistence.DynamoDB" Version="3.*" />
10+
<PackageReference Include="NServiceBus.Testing" Version="9.*" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Amazon.DynamoDBv2.Model;
2+
3+
namespace DynamoDB_3
4+
{
5+
internal class Assert
6+
{
7+
internal static void That(IReadOnlyCollection<TransactWriteItem> transactWriteItems, object value)
8+
{
9+
return;
10+
}
11+
}
12+
internal class Has
13+
{
14+
public static Count Count { get; internal set; }
15+
}
16+
17+
internal class Count
18+
{
19+
internal bool EqualTo(int v)
20+
{
21+
return true;
22+
}
23+
}
24+
25+
internal class TestAttribute : Attribute
26+
{
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using NServiceBus;
2+
3+
namespace DynamoDB_3;
4+
5+
public class OutboxConfig
6+
{
7+
void ConfigureSagaTable(EndpointConfiguration endpointConfiguration)
8+
{
9+
#region DynamoOutboxTableConfiguration
10+
11+
var outboxConfiguration = endpointConfiguration.EnableOutbox();
12+
outboxConfiguration.UseTable(new TableConfiguration
13+
{
14+
TableName = "MyOutboxTable",
15+
PartitionKeyName = "MyOutboxPartitionKey",
16+
SortKeyName = "MyOutboxSortKey",
17+
TimeToLiveAttributeName = "MyOutboxTtlAttribute"
18+
});
19+
#endregion
20+
}
21+
22+
void CleanupConfig(EndpointConfiguration endpointConfiguration)
23+
{
24+
#region DynamoDBOutboxCleanup
25+
26+
var outboxConfiguration = endpointConfiguration.EnableOutbox();
27+
outboxConfiguration.SetTimeToKeepDeduplicationData(TimeSpan.FromDays(14));
28+
29+
#endregion
30+
}
31+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using NServiceBus;
2+
3+
namespace DynamoDB_3;
4+
5+
public class SagaConfig
6+
{
7+
void ConfigureSagaTable(PersistenceExtensions<DynamoPersistence> persistence)
8+
{
9+
#region DynamoSagaTableConfiguration
10+
persistence.Sagas().Table = new TableConfiguration
11+
{
12+
TableName = "MySagaTable",
13+
PartitionKeyName = "MySagaPartitionKey",
14+
SortKeyName = "MySagaSortKey"
15+
};
16+
#endregion
17+
}
18+
19+
void PessimisticLocking(PersistenceExtensions<DynamoPersistence> persistence)
20+
{
21+
#region DynamoDBSagaPessimisticLocking
22+
23+
persistence.Sagas().UsePessimisticLocking = true;
24+
25+
#endregion
26+
27+
#region DynamoDBLeaseDuration
28+
29+
persistence.Sagas().LeaseDuration = TimeSpan.FromSeconds(15);
30+
31+
#endregion
32+
33+
#region DynamoDBLeaseAcquisitionTimeout
34+
35+
persistence.Sagas().LeaseAcquisitionTimeout = TimeSpan.FromSeconds(5);
36+
37+
#endregion
38+
}
39+
}

0 commit comments

Comments
 (0)