Joel
Joel

Reputation: 8948

Abort chain of activities for MassTransit Saga

I'm trying to figure out how to abort a chain of activities, if one activity decides that there is something wrong, and the Saga should be Finalized.

For example:

Initially(
    When(UpdateRequested)
        .Activity(x => x.OfType<InitialSetup>())
        .Activity(x => x.OfType<StartUpdating>())
        .TransitionTo(Updating)

InitialSetup will configure the Saga based on some information loaded from the database. Let's that that it realizes that the data needed is missing, and the Saga should be finalized, before StartUpdating activity is run.

How can I achieve that?

Upvotes: 0

Views: 312

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33268

You can throw an exception, catch it, and use the catch branch to finalize the saga.

Initially(
    When(UpdateRequested)
        .Activity(x => x.OfType<InitialSetup>()) // activity throws
        .Activity(x => x.OfType<StartUpdating>())
        .TransitionTo(Updating)
        .Catch<MissingDataException>(x => x.Finalize())
);

Upvotes: 1

Related Questions