I've created a saga and was wondering how to handle my exceptions during the execution of activities. Ideally, I would like to kill off that saga instance in some cases, immediately in the .Catch()
.
I've stumbled upon this thread: Understanding "Finalize" in MassTransit, my current approach is slightly different. In the .Catch()
I publish a SagaFaultedEvent
and transition to a Faulted
state:
.Catch<Exception>(e => e
.Publish(context => (ISagaFaultedEvent)new SagaFaultedEvent(context.Instance.Id))
.TransitionTo(Faulted)));
Then handle this event by logging the issue and finalizing the instance
During(Faulted,
When(SagaFaulted)
.Activity(x => x.OfInstanceType<LogFaultedSagaActivity>())
.Finalize());
This seems to work, however, in the answer to the mentioned thread, Chris says that the saga should be finalized directly there in the Catch()
, however, there's no Finalize()
available on the ExceptionActivityBinder
and I don't have access to the EventActivityBinder
there.
Am I missing something here (probably)? Is it possible to finalize the Saga directly in the Catch()
?
Support for this was added to Automatonymous
in 3.6.1, which was released today.