Is there a way to execute the compensation from faulted activity

550 Views Asked by At

Lets assume I have defined the routing slip activity. Within Execute method I would like to make several asynchronous service calls. Lets assume 3 service calls. Two of them succeed and one fails. Then I would like to execute compensate action of this activity in order to compensate the changes introduced by two succeeded service calls. From what I see the compensation only runs for previous activities, the current activity compensation has no chance to be invoked when there is exception somewhere in it. Is there a way to deal with it or I should change the approach?

I would like to achive sth similar to enter image description here using MassTransit.

1

There are 1 best solutions below

2
Chris Patterson On

You should have three separate activities, and execute them in order, so that as they succeed individually, they are added to the log. If an activity fails, the previous activities will be compensated.

By having all three calls in a single activity, you're going against the entire reason for having the routing slip and activities.