I am trying to learn more about Mass Transit as we are thinking about adopting it. I now have the class based Saga below, which works as expected:
public class EchoSaga : ISaga,
InitiatedBy<TextEntered>,
Orchestrates<TextEchoStart>,
Orchestrates<EchoEnd>
{
public Guid CorrelationId { get; set; }
public string CurrentState { get; set; }
public string Text { get; set; }
public Task Consume(ConsumeContext<TextEntered> context)
{
CurrentState = "Entered";
Text = context.Message.Text;
return Task.CompletedTask;
}
public Task Consume(ConsumeContext<TextEchoStart> context)
{
CurrentState = "Start";
Text = context.Message.Text;
return Task.CompletedTask;
}
public Task Consume(ConsumeContext<EchoEnd> context)
{
CurrentState = "End";
Text = context.Message.Text;
return Task.CompletedTask;
}
}
A class based Saga is different to a state machine Saga and is described more in the docs here in the Saga section: http://masstransit-project.com/MassTransit/understand/key-ideas.html.
How do I mark the Saga as finalized after EchoEnd is consumed so it is deleted from the database (I have already setup the repository)? If I was using a state machine Saga, then I could do this:
.Finalize()
.SetCompletedWhenFinalized()
How do I do this with a class based Saga?
I realise I may be going backwards a bit here, however I am trying to learn how Mass Transit started and where it is now to see if it meets our requirements. Very pleased with it so far.
If you cast the ConsumeContext
to SagaConsumeContext<TSaga, TMessage>
, there is a SetCompleted
method which signals the saga is complete and can be removed from the repository.
You may need to use context.GetPayload<SagaConsumeContext<TSaga, TMessage>>()
if casting directly doesn't work (due to proxy use in the pipeline).
来源:https://stackoverflow.com/questions/56516412/how-do-i-finalize-a-class-based-saga-so-that-it-is-deleted-from-the-sql-databas