我正在尝试处理Saga实例中的特定Fault
,如https://masstransit-project.com/MassTransit/usage/exceptions.html#faults中所述。在我的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;
});
}
但是,当发生Fault<CustomCommand>
时,处理程序中的代码未执行,并且Fault<CustomCommand>
消息进入..._skipped
队列。
我在做什么错?
CustomCommands
是否以Initial状态处理并引发异常?这将阻止保存传奇实例,因此,在发布故障之后,由于DuringAny
不包含Initial或Final状态,将导致忽略该故障。如果要在Initial状态下处理故障,则需要显式添加。
Initially(WhenError());
DuringAny(WhenError());