I have a MassTransit saga with InMemoryOutbox configuration:
public OrderStateMachine()
{
InstanceState(x => x.CurrentState);
Initially(
When(OrderClosed)
.Activity(x => x.OfType<OrderClosedActivity>())
.TransitionTo(Submitted)
);
}
Question: When using InMemoryOutbox, what executes first - the Activity or the Transition?
I need to understand the execution order because:
What I expect:
Submitted
happen first, then the Activity executes?Context: I'm using MassTransit with InMemoryOutbox for saga state management.
Can someone clarify the execution order and provide any official documentation references? I know how it works with Event publishing + TransitionTo, but i am not sure about activities.
Activities are executed, in order. Both the Activity call and the TransitionTo call are activities. So the activity is called, and then the instance current state is transitioned to Submitted.
If there were subsequent activities specified, those would be executed. EVEN if the state was transitioned to Final, they would STILL be executed.
The only thing the outbox defers is the delivery of messages produced to the broker, it doesn't change the way states, events, or activities are processed.
There are no incremental saves to the database, the instance is only saved once all activities have completed (or removed, if the instance was finalized and set to completed).