Reputation: 23
I am implementing MassTransit SAGA state machine with states "Initial" > "Pending Acknowledged" > "Acknowledged" > "Finalized" . The "Pending Acknowledged" and "Acknowledged" can be switched. But I would like to act do something after changing state from "Pending Acknowledged" to "Acknowledged".
Currently , I try to add thenAsync task after transition to "AcknowLedged". I found that the state will not be moved to "Acknowledged" when DoSomeThing task was called and action. It is not working as expect.
**During(PendingAcknowledged)**,
When(DoAcknowledged)
.ThenAsync(MarkAcknowledged)
.Then(context => Log.Information("{@DoAcknowledge}", context.Instance))
**.TransitionTo(Acknowledged),**
**.ThenAsync(DoSomeThing)**
Any suggestion ? How can I do it ?
Upvotes: 0
Views: 2073
Reputation: 33268
Upon event receipt, MassTransit:
Having multiple TransitionTo
activities in a state machine is allowed, but the saga instance will only be saved with the last state after all activities have completed.
So, from your example, this is entirely legal and will save the Acknowledged
state to the repository.
During(PendingAcknowledged),
When(DoAcknowledged)
.ThenAsync(MarkAcknowledged)
.Then(context => Log.Information("{@DoAcknowledge}", context.Instance))
.TransitionTo(Acknowledged),
.ThenAsync(DoSomeThing)
Upvotes: 2