Search code examples
masstransitrouting-slip

Outbox for routing slip in statemachine?


In one of my statemachine actions I create a routing slip to carry out a series of commands. This is done by calling

_busControl.Execute(routingSlip);

But sometimes the saga commit fails due to concurrency issues. Is there a "outbox" like mechanism to defer sending the routing slip to the bus until the saga is committed successfully?


Solution

  • Yes, you can use the outbox to defer sends:

    http://masstransit-project.com/MassTransit/usage/exceptions.html#outbox

    cfg.ReceiveEndpoint("input-queue", e =>
    {
        e.UseInMemoryOutbox();
    
        e.StateMachineSaga(...);
    });
    

    You will, however, need to execute the routing slip using the ConsumeContext in the state machine event handler, and not using _busControl. IBus or IBusControl should never be used inside a consumer. The documentation has more details.