From 8a98ddf24a3044965acf01f832a02ba3691e2e68 Mon Sep 17 00:00:00 2001 From: Jason Taylor Date: Tue, 29 Jul 2025 15:25:39 +1000 Subject: [PATCH 1/5] Remove InputLoopService --- .../DynamoDB_3/Client/InputLoopService.cs | 36 ---------------- .../DynamoDB_3/Client/Program.cs | 43 +++++++++++++++++-- .../DynamoDB_3/Server/Program.cs | 3 -- 3 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 samples/aws/dynamodb-transactions/DynamoDB_3/Client/InputLoopService.cs diff --git a/samples/aws/dynamodb-transactions/DynamoDB_3/Client/InputLoopService.cs b/samples/aws/dynamodb-transactions/DynamoDB_3/Client/InputLoopService.cs deleted file mode 100644 index 980ee0b3060..00000000000 --- a/samples/aws/dynamodb-transactions/DynamoDB_3/Client/InputLoopService.cs +++ /dev/null @@ -1,36 +0,0 @@ - -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using NServiceBus; -public class InputLoopService(IMessageSession messageSession) : BackgroundService -{ - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - Console.WriteLine("Press 'S' to send a StartOrder message to the server endpoint"); - Console.WriteLine("Press any other key to exit"); - - while (true) - { - var key = Console.ReadKey(); - Console.WriteLine(); - - if (key.Key == ConsoleKey.S) - { - var orderId = Guid.NewGuid(); - var startOrder = new StartOrder - { - OrderId = orderId - }; - - await messageSession.Send("Samples.DynamoDB.Transactions.Server", startOrder); - Console.WriteLine($"StartOrder Message sent to Server with OrderId {orderId}"); - continue; - } - break; - } - - - } -} diff --git a/samples/aws/dynamodb-transactions/DynamoDB_3/Client/Program.cs b/samples/aws/dynamodb-transactions/DynamoDB_3/Client/Program.cs index d6be2e0a541..8988a6d6afc 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_3/Client/Program.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_3/Client/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -7,16 +8,52 @@ Console.Title = "Client"; var builder = Host.CreateApplicationBuilder(args); -builder.Services.AddHostedService(); var endpointConfiguration = new EndpointConfiguration("Samples.DynamoDB.Transactions.Client"); endpointConfiguration.UseSerialization(); endpointConfiguration.UseTransport(); - Console.WriteLine("Press any key, the application is starting"); Console.ReadKey(); Console.WriteLine("Starting..."); builder.UseNServiceBus(endpointConfiguration); -await builder.Build().RunAsync(); + +var host = builder.Build(); + +// Get the required services +var messageSession = host.Services.GetRequiredService(); +// Register a cancellation token to gracefully handle application shutdown +var ct = host.Services.GetRequiredService().ApplicationStopping; + +Console.WriteLine("Press 'S' to send a StartOrder message to the server endpoint."); +Console.WriteLine("Press Ctrl+C to shut down."); + +// Wait for user input to publish messages +while (!ct.IsCancellationRequested) +{ + if (!Console.KeyAvailable) + { + // If no key is pressed, wait for a short time before checking again + await Task.Delay(100, CancellationToken.None); + continue; + } + + var key = Console.ReadKey(); + Console.WriteLine(); + + if (key.Key == ConsoleKey.S) + { + var orderId = Guid.NewGuid(); + var startOrder = new StartOrder + { + OrderId = orderId + }; + + await messageSession.Send("Samples.DynamoDB.Transactions.Server", startOrder); + Console.WriteLine($"StartOrder Message sent to Server with OrderId {orderId}"); + } +} + +// Wait for the host to stop gracefully +await host.StopAsync(); diff --git a/samples/aws/dynamodb-transactions/DynamoDB_3/Server/Program.cs b/samples/aws/dynamodb-transactions/DynamoDB_3/Server/Program.cs index 67f2cd333c4..a37cd00b87c 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_3/Server/Program.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_3/Server/Program.cs @@ -4,7 +4,6 @@ using Microsoft.Extensions.Hosting; using NServiceBus; - Console.Title = "Server"; var builder = Host.CreateApplicationBuilder(args); @@ -39,8 +38,6 @@ }); endpointConfiguration.EnableInstallers(); - - Console.WriteLine("Press any key, the application is starting"); Console.ReadKey(); Console.WriteLine("Starting..."); From 1f664a0996086d3a79b6928b0543d25cafee72cc Mon Sep 17 00:00:00 2001 From: Jason Taylor Date: Tue, 29 Jul 2025 15:26:37 +1000 Subject: [PATCH 2/5] Clone DynamoDB_3 --- .../DynamoDB_4/Client/Client.csproj | 14 ++++ .../Client/OrderCompletedHandler.cs | 13 ++++ .../DynamoDB_4/Client/Program.cs | 59 +++++++++++++++++ .../DynamoDB_4/DynamoDB.StartupProjects.txt | 2 + .../DynamoDB_4/DynamoDB.sln | 34 ++++++++++ .../DynamoDB_4/Server/CompleteOrder.cs | 7 ++ .../DynamoDB_4/Server/OrderSaga.cs | 64 +++++++++++++++++++ .../DynamoDB_4/Server/OrderSagaData.cs | 12 ++++ .../DynamoDB_4/Server/OrderShipped.cs | 8 +++ .../Server/OrderShippingInformation.cs | 10 +++ .../OrderShippingInformationExtensions.cs | 15 +++++ .../DynamoDB_4/Server/Program.cs | 46 +++++++++++++ .../DynamoDB_4/Server/Server.csproj | 15 +++++ .../DynamoDB_4/Server/ShipOrder.cs | 8 +++ .../DynamoDB_4/Server/ShipOrderHandler.cs | 43 +++++++++++++ .../SharedMessages/OrderCompleted.cs | 8 +++ .../SharedMessages/SharedMessages.csproj | 9 +++ .../DynamoDB_4/SharedMessages/StartOrder.cs | 8 +++ .../DynamoDB_4/docker-compose.yml | 8 +++ 19 files changed, 383 insertions(+) create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.StartupProjects.txt create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.sln create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSaga.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSagaData.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/docker-compose.yml diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj new file mode 100644 index 00000000000..eb958aab45b --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj @@ -0,0 +1,14 @@ + + + net9.0;net8.0 + Exe + 12.0 + + + + + + + + + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs new file mode 100644 index 00000000000..c0954d65151 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using NServiceBus; + +public class OrderCompletedHandler(ILogger logger) : + IHandleMessages +{ + public Task Handle(OrderCompleted message, IMessageHandlerContext context) + { + logger.LogInformation("Received OrderCompleted for OrderId {OrderId}", message.OrderId); + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs new file mode 100644 index 00000000000..8988a6d6afc --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs @@ -0,0 +1,59 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using NServiceBus; + +Console.Title = "Client"; + +var builder = Host.CreateApplicationBuilder(args); + +var endpointConfiguration = new EndpointConfiguration("Samples.DynamoDB.Transactions.Client"); +endpointConfiguration.UseSerialization(); +endpointConfiguration.UseTransport(); + +Console.WriteLine("Press any key, the application is starting"); +Console.ReadKey(); +Console.WriteLine("Starting..."); + +builder.UseNServiceBus(endpointConfiguration); + +var host = builder.Build(); + +// Get the required services +var messageSession = host.Services.GetRequiredService(); +// Register a cancellation token to gracefully handle application shutdown +var ct = host.Services.GetRequiredService().ApplicationStopping; + +Console.WriteLine("Press 'S' to send a StartOrder message to the server endpoint."); +Console.WriteLine("Press Ctrl+C to shut down."); + +// Wait for user input to publish messages +while (!ct.IsCancellationRequested) +{ + if (!Console.KeyAvailable) + { + // If no key is pressed, wait for a short time before checking again + await Task.Delay(100, CancellationToken.None); + continue; + } + + var key = Console.ReadKey(); + Console.WriteLine(); + + if (key.Key == ConsoleKey.S) + { + var orderId = Guid.NewGuid(); + var startOrder = new StartOrder + { + OrderId = orderId + }; + + await messageSession.Send("Samples.DynamoDB.Transactions.Server", startOrder); + Console.WriteLine($"StartOrder Message sent to Server with OrderId {orderId}"); + } +} + +// Wait for the host to stop gracefully +await host.StopAsync(); diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.StartupProjects.txt b/samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.StartupProjects.txt new file mode 100644 index 00000000000..a2d7c204577 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.StartupProjects.txt @@ -0,0 +1,2 @@ +Client\Client.csproj +Server\Server.csproj \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.sln b/samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.sln new file mode 100644 index 00000000000..bf08c42b9f0 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/DynamoDB.sln @@ -0,0 +1,34 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29728.190 +MinimumVisualStudioVersion = 15.0.26730.12 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{48F718EE-6C45-41BA-80EC-81BF34D4A623}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedMessages", "SharedMessages\SharedMessages.csproj", "{DD438DB2-9C03-4BC0-BA52-BB7A35098458}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{2FE71442-7F81-428E-B945-D564850D6564}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4043293B-171D-4E7D-8E47-A9957327AD20}" + ProjectSection(SolutionItems) = preProject + docker-compose.yml = docker-compose.yml + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48F718EE-6C45-41BA-80EC-81BF34D4A623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48F718EE-6C45-41BA-80EC-81BF34D4A623}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD438DB2-9C03-4BC0-BA52-BB7A35098458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD438DB2-9C03-4BC0-BA52-BB7A35098458}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FE71442-7F81-428E-B945-D564850D6564}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FE71442-7F81-428E-B945-D564850D6564}.Debug|Any CPU.Build.0 = Debug|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BB6580A8-3A40-4373-B226-A86402536658} + EndGlobalSection +EndGlobal diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs new file mode 100644 index 00000000000..0dca566fa8a --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs @@ -0,0 +1,7 @@ +using System; + +public class CompleteOrder +{ + public Guid OrderId { get; set; } + public string OrderDescription { get; set; } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSaga.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSaga.cs new file mode 100644 index 00000000000..b5e042f668c --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSaga.cs @@ -0,0 +1,64 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using NServiceBus; + +#region thesaga + +public class OrderSaga(ILogger logger): + Saga, + IAmStartedByMessages, + IHandleMessages, + IHandleTimeouts +{ + protected override void ConfigureHowToFindSaga(SagaPropertyMapper mapper) + { + mapper.MapSaga(saga => saga.OrderId) + .ToMessage(msg => msg.OrderId) + .ToMessage(msg => msg.OrderId); + } + + public async Task Handle(StartOrder message, IMessageHandlerContext context) + { + var orderDescription = $"The saga for order {message.OrderId}"; + Data.OrderDescription = orderDescription; + + logger.LogInformation("Received StartOrder message {OrderId}. Starting Saga", Data.OrderId); + + var shipOrder = new ShipOrder + { + OrderId = message.OrderId + }; + + logger.LogInformation("Order will complete in 5 seconds"); + var timeoutData = new CompleteOrder + { + OrderDescription = orderDescription, + OrderId = Data.OrderId, + }; + + await Task.WhenAll( + context.SendLocal(shipOrder), + RequestTimeout(context, TimeSpan.FromSeconds(5), timeoutData) + ); + } + + public Task Handle(OrderShipped message, IMessageHandlerContext context) + { + logger.LogInformation("Order with OrderId {OrderId} shipped on {ShippingDate}", Data.OrderId, message.ShippingDate); + return Task.CompletedTask; + } + + public async Task Timeout(CompleteOrder state, IMessageHandlerContext context) + { + logger.LogInformation("Saga with OrderId {OrderId} completed", Data.OrderId); + MarkAsComplete(); + var orderCompleted = new OrderCompleted + { + OrderId = Data.OrderId + }; + await context.Publish(orderCompleted); + } +} + +#endregion \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSagaData.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSagaData.cs new file mode 100644 index 00000000000..b980096ef58 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderSagaData.cs @@ -0,0 +1,12 @@ +using System; +using NServiceBus; + +#region sagadata + +public class OrderSagaData : + ContainSagaData +{ + public Guid OrderId { get; set; } + public string OrderDescription { get; set; } +} +#endregion \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs new file mode 100644 index 00000000000..7dafb1d7d83 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs @@ -0,0 +1,8 @@ +using System; +using NServiceBus; + +public class OrderShipped : IEvent +{ + public Guid OrderId { get; set; } + public DateTimeOffset ShippingDate { get; set; } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs new file mode 100644 index 00000000000..1c19ae338c9 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs @@ -0,0 +1,10 @@ +using System; + +public class OrderShippingInformation +{ + public Guid Id { get; set; } + + public Guid OrderId { get; set; } + + public DateTimeOffset ShippedAt { get; set; } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs new file mode 100644 index 00000000000..c4c9f93236a --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; +using NServiceBus.Persistence.DynamoDB; + +public static class OrderShippingInformationExtensions +{ + public static Dictionary ToMap(this OrderShippingInformation orderShippingInformation) + { + var attributeMap = Mapper.ToMap(orderShippingInformation); + var orderShippingInformationId = orderShippingInformation.Id.ToString(); + attributeMap["PK"] = new AttributeValue(orderShippingInformationId); + attributeMap["SK"] = new AttributeValue(orderShippingInformationId); + return attributeMap; + } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs new file mode 100644 index 00000000000..a37cd00b87c --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs @@ -0,0 +1,46 @@ +using System; +using Amazon.DynamoDBv2; +using Amazon.Runtime; +using Microsoft.Extensions.Hosting; +using NServiceBus; + +Console.Title = "Server"; + +var builder = Host.CreateApplicationBuilder(args); + +#region DynamoDBConfig + +var amazonDynamoDbClient = new AmazonDynamoDBClient( + new BasicAWSCredentials("localdb", "localdb"), + new AmazonDynamoDBConfig + { + ServiceURL = "http://localhost:8000" + }); + + +var endpointConfiguration = new EndpointConfiguration("Samples.DynamoDB.Transactions.Server"); +endpointConfiguration.UseSerialization(); + +var persistence = endpointConfiguration.UsePersistence(); +persistence.DynamoClient(amazonDynamoDbClient); +persistence.UseSharedTable(new TableConfiguration +{ + TableName = "Samples.DynamoDB.Transactions" +}); + +endpointConfiguration.EnableOutbox(); + +#endregion + +endpointConfiguration.UseTransport(new LearningTransport +{ + TransportTransactionMode = TransportTransactionMode.ReceiveOnly +}); +endpointConfiguration.EnableInstallers(); + +Console.WriteLine("Press any key, the application is starting"); +Console.ReadKey(); +Console.WriteLine("Starting..."); + +builder.UseNServiceBus(endpointConfiguration); +await builder.Build().RunAsync(); diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj new file mode 100644 index 00000000000..334d6a56690 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj @@ -0,0 +1,15 @@ + + + net9.0;net8.0 + Exe + 12.0 + Linux + + + + + + + + + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs new file mode 100644 index 00000000000..495d5fb5d04 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs @@ -0,0 +1,8 @@ +using System; +using NServiceBus; + +public class ShipOrder : + IMessage +{ + public Guid OrderId { get; set; } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs new file mode 100644 index 00000000000..eeca0430552 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs @@ -0,0 +1,43 @@ +using System; +using System.Threading.Tasks; +using Amazon.DynamoDBv2.Model; +using Microsoft.Extensions.Logging; +using NServiceBus; + +public class ShipOrderHandler(ILogger logger) : + IHandleMessages +{ + public async Task Handle(ShipOrder message, IMessageHandlerContext context) + { + #region DynamoDBStorageSession + + var orderShippingInformation = new OrderShippingInformation + { + Id = Guid.NewGuid(), + OrderId = message.OrderId, + ShippedAt = DateTimeOffset.UtcNow, + }; + + var session = context.SynchronizedStorageSession.DynamoPersistenceSession(); + + session.Add(new TransactWriteItem + { + Put = new Put + { + TableName = "Samples.DynamoDB.Transactions", + Item = orderShippingInformation.ToMap() + } + }); + + #endregion + + logger.LogInformation("Order Shipped. OrderId {OrderId}", message.OrderId); + + await context.Publish(new OrderShipped + { + OrderId = orderShippingInformation.OrderId, + ShippingDate = orderShippingInformation.ShippedAt + }); + } + +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs new file mode 100644 index 00000000000..961ddd5bdc8 --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs @@ -0,0 +1,8 @@ +using System; +using NServiceBus; + +public class OrderCompleted : + IEvent +{ + public Guid OrderId { get; set; } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj new file mode 100644 index 00000000000..72aec1f4abf --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj @@ -0,0 +1,9 @@ + + + net9.0;net8.0 + 12.0 + + + + + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs new file mode 100644 index 00000000000..838d5a8532a --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs @@ -0,0 +1,8 @@ +using System; +using NServiceBus; + +public class StartOrder : + IMessage +{ + public Guid OrderId { get; set; } +} \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/docker-compose.yml b/samples/aws/dynamodb-transactions/DynamoDB_4/docker-compose.yml new file mode 100644 index 00000000000..daf9293955f --- /dev/null +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.8' +services: + dynamodb-local: + command: "-jar DynamoDBLocal.jar -sharedDb -inMemory true" + image: "amazon/dynamodb-local:latest" + container_name: dynamodb-local + ports: + - "8000:8000" \ No newline at end of file From 01769b7acbf2f45b96f1c5725f2bef5f6d397c75 Mon Sep 17 00:00:00 2001 From: Jason Taylor Date: Tue, 29 Jul 2025 16:19:39 +1000 Subject: [PATCH 3/5] Upgrade to .NET 10 --- .../DynamoDB_4/Client/Client.csproj | 9 +++++---- .../DynamoDB_4/Client/OrderCompletedHandler.cs | 4 +--- .../dynamodb-transactions/DynamoDB_4/Client/Program.cs | 10 +--------- .../DynamoDB_4/Server/CompleteOrder.cs | 2 -- .../DynamoDB_4/Server/OrderShipped.cs | 5 +---- .../DynamoDB_4/Server/OrderShippingInformation.cs | 4 +--- .../Server/OrderShippingInformationExtensions.cs | 1 - .../dynamodb-transactions/DynamoDB_4/Server/Program.cs | 8 +------- .../DynamoDB_4/Server/Server.csproj | 9 +++++---- .../DynamoDB_4/Server/ShipOrder.cs | 5 +---- .../DynamoDB_4/Server/ShipOrderHandler.cs | 5 +---- .../DynamoDB_4/SharedMessages/OrderCompleted.cs | 3 --- .../DynamoDB_4/SharedMessages/SharedMessages.csproj | 7 ++++--- .../DynamoDB_4/SharedMessages/StartOrder.cs | 3 --- .../dynamodb-transactions/DynamoDB_4/prerelease.txt | 0 15 files changed, 21 insertions(+), 54 deletions(-) create mode 100644 samples/aws/dynamodb-transactions/DynamoDB_4/prerelease.txt diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj index eb958aab45b..2809756226b 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj @@ -1,14 +1,15 @@ - net9.0;net8.0 + net10.0 Exe - 12.0 + preview + enable - - + + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs index c0954d65151..9e01f56f245 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/OrderCompletedHandler.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using NServiceBus; +using Microsoft.Extensions.Logging; public class OrderCompletedHandler(ILogger logger) : IHandleMessages diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs index 8988a6d6afc..2ac756ce6b6 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Program.cs @@ -1,9 +1,5 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using NServiceBus; Console.Title = "Client"; @@ -13,10 +9,6 @@ endpointConfiguration.UseSerialization(); endpointConfiguration.UseTransport(); -Console.WriteLine("Press any key, the application is starting"); -Console.ReadKey(); -Console.WriteLine("Starting..."); - builder.UseNServiceBus(endpointConfiguration); var host = builder.Build(); diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs index 0dca566fa8a..af886d17bed 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/CompleteOrder.cs @@ -1,5 +1,3 @@ -using System; - public class CompleteOrder { public Guid OrderId { get; set; } diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs index 7dafb1d7d83..14fc2353a5f 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShipped.cs @@ -1,7 +1,4 @@ -using System; -using NServiceBus; - -public class OrderShipped : IEvent +public class OrderShipped : IEvent { public Guid OrderId { get; set; } public DateTimeOffset ShippingDate { get; set; } diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs index 1c19ae338c9..60d899af332 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformation.cs @@ -1,6 +1,4 @@ -using System; - -public class OrderShippingInformation +public class OrderShippingInformation { public Guid Id { get; set; } diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs index c4c9f93236a..de42e4cef37 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/OrderShippingInformationExtensions.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Amazon.DynamoDBv2.Model; using NServiceBus.Persistence.DynamoDB; diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs index a37cd00b87c..c7e3284a740 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Program.cs @@ -1,8 +1,6 @@ -using System; -using Amazon.DynamoDBv2; +using Amazon.DynamoDBv2; using Amazon.Runtime; using Microsoft.Extensions.Hosting; -using NServiceBus; Console.Title = "Server"; @@ -38,9 +36,5 @@ }); endpointConfiguration.EnableInstallers(); -Console.WriteLine("Press any key, the application is starting"); -Console.ReadKey(); -Console.WriteLine("Starting..."); - builder.UseNServiceBus(endpointConfiguration); await builder.Build().RunAsync(); diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj index 334d6a56690..9a5b14108a9 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj @@ -1,13 +1,14 @@ - net9.0;net8.0 + net10.0 Exe - 12.0 + preview Linux + enable - - + + diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs index 495d5fb5d04..38d2595e2ee 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrder.cs @@ -1,7 +1,4 @@ -using System; -using NServiceBus; - -public class ShipOrder : +public class ShipOrder : IMessage { public Guid OrderId { get; set; } diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs index eeca0430552..41e477202a7 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/ShipOrderHandler.cs @@ -1,8 +1,5 @@ -using System; -using System.Threading.Tasks; -using Amazon.DynamoDBv2.Model; +using Amazon.DynamoDBv2.Model; using Microsoft.Extensions.Logging; -using NServiceBus; public class ShipOrderHandler(ILogger logger) : IHandleMessages diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs index 961ddd5bdc8..ba9025482e1 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/OrderCompleted.cs @@ -1,6 +1,3 @@ -using System; -using NServiceBus; - public class OrderCompleted : IEvent { diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj index 72aec1f4abf..73850992d51 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj @@ -1,9 +1,10 @@ - net9.0;net8.0 - 12.0 + net10.0 + preview + enable - + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs index 838d5a8532a..fea64898be8 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/StartOrder.cs @@ -1,6 +1,3 @@ -using System; -using NServiceBus; - public class StartOrder : IMessage { diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/prerelease.txt b/samples/aws/dynamodb-transactions/DynamoDB_4/prerelease.txt new file mode 100644 index 00000000000..e69de29bb2d From c4cbffe2c057b342c57f0e3017e06b81a218e117 Mon Sep 17 00:00:00 2001 From: Jason Taylor Date: Wed, 30 Jul 2025 09:47:04 +1000 Subject: [PATCH 4/5] Revert to alpha.1 --- .../aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj | 4 ++-- .../aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj | 4 ++-- .../DynamoDB_4/SharedMessages/SharedMessages.csproj | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj index 2809756226b..0f1df8cf510 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj @@ -9,7 +9,7 @@ - - + + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj index 9a5b14108a9..15c3fc63ed8 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj @@ -7,8 +7,8 @@ enable - - + + diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj index 73850992d51..09002cbbf5a 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj @@ -5,6 +5,6 @@ enable - + \ No newline at end of file From 0ddb1aa6f5b516745455173ccb553586aaec38a7 Mon Sep 17 00:00:00 2001 From: Jason Taylor Date: Tue, 19 Aug 2025 14:33:46 +1000 Subject: [PATCH 5/5] Upgrade NSB versions --- .../aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj | 4 ++-- .../aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj | 4 ++-- .../DynamoDB_4/SharedMessages/SharedMessages.csproj | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj index 0f1df8cf510..628cff5b213 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Client/Client.csproj @@ -9,7 +9,7 @@ - - + + \ No newline at end of file diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj index 15c3fc63ed8..9a5b14108a9 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/Server/Server.csproj @@ -7,8 +7,8 @@ enable - - + + diff --git a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj index 09002cbbf5a..04e7e339b20 100644 --- a/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj +++ b/samples/aws/dynamodb-transactions/DynamoDB_4/SharedMessages/SharedMessages.csproj @@ -5,6 +5,6 @@ enable - + \ No newline at end of file