简体   繁体   中英

MassTransit handling Faults in Saga

I'm trying to handle specific Fault inside Saga instance like described in https://masstransit-project.com/MassTransit/usage/exceptions.html#faults . In my StateMachine class I have:

Event(
    () => OnError,
    x => x
        .CorrelateById(context => context.Message.Message.CorrelationId))

DuringAny(WhenError());

...

public Event<CustomCommand> CustomCommandReceived { get; protected set; }

public Event<Fault<CustomCommand>> OnError { get; protected set; }

...

private EventActivityBinder<RequestSaga, Fault<CustomCommand>> WhenError()
{
    return When(OnError)
        .Then(context =>
        {
            context.Instance.Status = RequestProcessingStatus.Error;
        });
}

But when Fault<CustomCommand> occured, code inside handler did'not execute and Fault<CustomCommand> message goes to ..._skipped queue.

What am I doing wrong??

Is CustomCommands handled in the Initial state, and throwing the exception? That would prevent the saga instance from being saved, and thus after the fault is published, would cause the fault to be ignored since DuringAny does not include the Initial or Final states. If you want to handle the fault in the Initial state, you need to add it explicitly.

Initially(WhenError());
DuringAny(WhenError());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM