Catch exception after retries inside saga

68 views Asked by At

I'm working on a POC using Kafka and Masstransit and I just stumble upon a weird scenario. I'm using a very simple retry police which basically retries at any exception during the execution flow. It works fine, that is, it retries at everything and throws an EventExecutionException exception. The problem is that I can't catch this (or any) exception this goes through a retry inside a .catch<> method.

When I define a Saga block like the bellow one it catches the exception right away, so don't retry it. I wonder if there's a way to "wait" the retries and then catch the exception and work on some sort of compensation inside the saga .catch<> block.

Part of my saga:

Initially(
    When(OrderRequestedEvent)
        .InitializeSaga()
        .Then(context => LogContext.Info?.Log("Order requested: {0}", context.Saga.CorrelationId))
        .Activity(config => config.OfType<ReceiveOrderRequestStepActivity>())
        .TransitionTo(ValidatingCustomer)
        .Catch<EventExecutionException>(p => p.TransitionTo(Faulted)
            .Activity(x => x.OfType<ReceiveOrderRequestStepActivity>())));

In this scenario, I'm trying to handle the thrown exception inside the Faulted method of an IStateMachineActivity.

This is my very simple retry policy configuration:

rider.AddSagaStateMachine<OrderRequestStateMachine, OrderRequestSagaInstance>(c =>
{
    c.UseMessageRetry(r =>
    {
        r.Interval(kafkaTopics.MaxRetriesAttempts, TimeSpan.FromSeconds(3));
    });
}).InMemoryRepository();
0

There are 0 answers