Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeremy D. Miller
authored and
Jeremy D. Miller
committed
Jul 8, 2022
1 parent
77bb561
commit b1c00a2
Showing
14 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Jasper/Persistence/Sagas/DisregardIfStateDoesNotExistFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using LamarCodeGeneration; | ||
using LamarCodeGeneration.Frames; | ||
using LamarCodeGeneration.Model; | ||
|
||
namespace Jasper.Persistence.Sagas; | ||
|
||
public class DisregardIfStateDoesNotExistFrame : SyncFrame | ||
{ | ||
private readonly Variable _saga; | ||
|
||
public DisregardIfStateDoesNotExistFrame(Variable saga) | ||
{ | ||
_saga = saga; | ||
uses.Add(_saga); | ||
} | ||
|
||
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) | ||
{ | ||
writer.Write($"if ({_saga.Usage} == null) return;"); | ||
Next?.GenerateCode(method, writer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Baseline.Dates; | ||
using Jasper; | ||
|
||
namespace OrderSagaSample; | ||
|
||
public record StartOrder(string Id); | ||
|
||
public record CompleteOrder(string Id); | ||
|
||
public record OrderTimeout(string Id) : TimeoutMessage(1.Minutes()); | ||
|
||
public class Order : Saga | ||
{ | ||
public string? Id { get; set; } | ||
|
||
public OrderTimeout Start(StartOrder order, ILogger<Order> logger) | ||
{ | ||
Id = order.Id; // defining the Saga Id. | ||
|
||
logger.LogInformation("Got a new order with id {Id}", order.Id); | ||
// creating a timeout message for the saga | ||
return new OrderTimeout(order.Id); | ||
} | ||
|
||
public void Handle(CompleteOrder complete, ILogger<Order> logger) | ||
{ | ||
logger.LogInformation("Completing order {Id}", complete.Id); | ||
|
||
// That's it, we're done. Delete the saga state after the message is done. | ||
MarkCompleted(); | ||
} | ||
|
||
public void Handle(OrderTimeout timeout, ILogger<Order> logger) | ||
{ | ||
logger.LogInformation("Applying timeout to order {Id}", timeout.Id); | ||
|
||
// That's it, we're done. Delete the saga state after the message is done. | ||
MarkCompleted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<LangVersion>10</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Jasper.Persistence.Marten\Jasper.Persistence.Marten.csproj" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Jasper; | ||
using Jasper.Persistence.Marten; | ||
using Marten; | ||
using Oakton; | ||
using Oakton.Resources; | ||
using OrderSagaSample; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Not 100% necessary, but enables some extra command line diagnostics | ||
builder.Host.ApplyOaktonExtensions(); | ||
|
||
// Adding Marten | ||
builder.Services.AddMarten(opts => | ||
{ | ||
var connectionString = builder.Configuration.GetConnectionString("Marten"); | ||
opts.Connection(connectionString); | ||
opts.DatabaseSchemaName = "orders"; | ||
}) | ||
|
||
// Adding the Jasper integration for Marten. | ||
.IntegrateWithJasper(); | ||
|
||
|
||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
// Do all necessary database setup on startup | ||
builder.Services.AddResourceSetupOnStartup(); | ||
|
||
// The defaults are good enough here | ||
builder.Host.UseJasper(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Just delegating to Jasper's local command bus for all | ||
app.MapPost("/start", (StartOrder start, ICommandBus bus) => bus.InvokeAsync(start)); | ||
app.MapPost("/complete", (StartOrder start, ICommandBus bus) => bus.InvokeAsync(start)); | ||
app.MapGet("/all", (IQuerySession session) => session.Query<Order>().ToListAsync()); | ||
|
||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
|
||
return await app.RunOaktonCommands(args); | ||
|
||
|
||
|
||
|
13 changes: 13 additions & 0 deletions
13
src/Samples/OrderSagaSample/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"profiles": { | ||
"OrderSagaSample": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:5252", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Order Saga Sample | ||
|
||
|
||
## TODO | ||
|
||
-- make all local endpoints be durable | ||
-- give up on Alba specs | ||
-- test for TimeoutMessage on sagas that do not exist | ||
-- streamline Program file again | ||
-- fix transaction issue in DurabilityAgent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"Marten": "Host=localhost;Port=5433;Database=postgres;Username=postgres;password=postgres" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters