Skip to content

Instantly share code, notes, and snippets.

@flew2bits
Last active January 29, 2024 16:37
Show Gist options
  • Save flew2bits/e44d01c6401ea003a0be96d02fab39c5 to your computer and use it in GitHub Desktop.
Save flew2bits/e44d01c6401ea003a0be96d02fab39c5 to your computer and use it in GitHub Desktop.
Sample Repro demonstrating issue with saga ids
using Marten;
using Oakton;
using Wolverine;
using Wolverine.Http;
using Wolverine.Marten;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseWolverine();
builder.Host.ApplyOaktonExtensions();
builder.Services.AddMarten(opt =>
{
opt.Connection("Host=localhost;Port=5434;Database=postgres;User ID=postgres;Password=pgsql");
})
.UseLightweightSessions()
.IntegrateWithWolverine();
var app = builder.Build();
app.MapWolverineEndpoints();
await app.RunOaktonCommands(args);
public static class RequestEndpoints
{
[WolverinePost("/message2")]
public static (IResult, MessageTwo) Handle(MessageTwo msg) => (Results.Accepted(), msg);
[WolverinePost("/message3")]
public static (IResult, MessageThree) Handle(MessageThree msg) => (Results.Accepted(), msg);
}
public class MySaga : Saga
{
public Guid Id { get; set; }
public int SagaData { get; set; }
[WolverinePost("/message1")]
public static (IResult, MySaga) Start(MessageOne msg) =>
(Results.Accepted(), new MySaga { Id = msg.Id, SagaData = 5 });
public void Handle(MessageTwo msg)
{
SagaData--;
if (SagaData == 0) MarkCompleted();
}
public void Handle(MessageThree msg)
{
SagaData--;
if (SagaData == 0) MarkCompleted();
}
}
public record MessageOne(Guid Id);
public record MessageTwo(Guid Id, Guid MySagaId);
public record MessageThree(Guid Id, Guid SagaId);
# This will start a new saga with the given id; the SagaData is initialized to 5
POST http://localhost:5195/message1
Content-Type: application/json
{ "Id": "3F4D5FDE-8FB4-42E3-AA18-4B5A972316E7" }
###
# This will get accepted, but the saga won't be found and will produce an exception (SagaData will still = 5)
POST http://localhost:5195/message2
Content-Type: application/json
{ "MySagaId": "3F4D5FDE-8FB4-42E3-AA18-4B5A972316E7", "Id": "E126BE12-2E34-44F6-8F5B-7A28F2E66901" }
###
# This gets accepted, and the saga is found; SagaData will be 4. If you execute this 5 times, the saga will be
# marked completed.
POST http://localhost:5195/message3
Content-Type: application/json
{ "SagaId": "3F4D5FDE-8FB4-42E3-AA18-4B5A972316E7", "Id": "A1990C07-C000-4850-8BAD-40A80E5D209E" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment