简体   繁体   English

MassTransit 在 Saga 中处理故障

[英]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 .我正在尝试处理 Saga 实例中的特定Faulthttps://masstransit-project.com/MassTransit/usage/exceptions.html#faults 中所述 In my StateMachine class I have:在我的StateMachine课程中,我有:

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.但是当Fault<CustomCommand>发生时,处理程序中的代码没有执行并且Fault<CustomCommand>消息进入..._skipped队列。

What am I doing wrong??我究竟做错了什么??

Is CustomCommands handled in the Initial state, and throwing the exception? CustomCommands是否在初始状态下处理并抛出异常? 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.这将阻止保存 saga 实例,因此在发布错误后,将导致错误被忽略,因为DuringAny不包括初始最终状态。 If you want to handle the fault in the Initial state, you need to add it explicitly.如果要处理Initial状态下的故障,需要显式添加。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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