How to trigger the execution of the compensation flow for the activities used within an Automatonymous state...
up vote
0
down vote
favorite
My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance>
to handle that, discarding the changes made in the Execute
method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute
method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.
Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy
based on BehaviorContext
and the exception thrown. The only next Behavior
I could pass would be the one inserted into that Activity
's Execute
method, but logically that means I'm compensating in the wrong direction as that next Behavior
is actually to be executed after this one succeeds, so I'd compensate too much.
I also tried to use the Catch
in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder
present.
Is there any good way to trigger the compensation flow of the activities?
masstransit saga automatonymous
add a comment |
up vote
0
down vote
favorite
My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance>
to handle that, discarding the changes made in the Execute
method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute
method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.
Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy
based on BehaviorContext
and the exception thrown. The only next Behavior
I could pass would be the one inserted into that Activity
's Execute
method, but logically that means I'm compensating in the wrong direction as that next Behavior
is actually to be executed after this one succeeds, so I'd compensate too much.
I also tried to use the Catch
in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder
present.
Is there any good way to trigger the compensation flow of the activities?
masstransit saga automatonymous
Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14
Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23
I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33
You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance>
to handle that, discarding the changes made in the Execute
method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute
method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.
Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy
based on BehaviorContext
and the exception thrown. The only next Behavior
I could pass would be the one inserted into that Activity
's Execute
method, but logically that means I'm compensating in the wrong direction as that next Behavior
is actually to be executed after this one succeeds, so I'd compensate too much.
I also tried to use the Catch
in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder
present.
Is there any good way to trigger the compensation flow of the activities?
masstransit saga automatonymous
My activities throw exceptions from time to time during the execution, so I've implemented the Faulted methods of Activity<TInstance>
to handle that, discarding the changes made in the Execute
method. I thought that there's some wiring underneath in Automatonymous that makes it so that the Faulted method executes when the Execute
method throws an exception and then calls the Faulted methods for the activities that were executed already. It turns out that there's no such thing, as my Faulted methods are never executed.
Should I call those myself in a try/catch block instead? I could produce the BehaviorExceptionContextProxy
based on BehaviorContext
and the exception thrown. The only next Behavior
I could pass would be the one inserted into that Activity
's Execute
method, but logically that means I'm compensating in the wrong direction as that next Behavior
is actually to be executed after this one succeeds, so I'd compensate too much.
I also tried to use the Catch
in the state machine, which does handle the exception, however, I couldn't find any way to start the execution of the compensation flow for the activity that failed when I only have the ExceptionActivityBinder
present.
Is there any good way to trigger the compensation flow of the activities?
masstransit saga automatonymous
masstransit saga automatonymous
asked Nov 22 at 13:42
Slowacki
121311
121311
Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14
Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23
I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33
You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40
add a comment |
Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14
Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23
I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33
You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40
Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14
Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14
Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23
Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23
I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33
I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33
You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40
You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.
When an activity throws an exception, the Faulted
method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted
method of those activities just calls the next activity in the behavior.
A Catch
activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).
Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.
When an activity throws an exception, the Faulted
method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted
method of those activities just calls the next activity in the behavior.
A Catch
activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).
Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
add a comment |
up vote
1
down vote
accepted
An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.
When an activity throws an exception, the Faulted
method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted
method of those activities just calls the next activity in the behavior.
A Catch
activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).
Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.
When an activity throws an exception, the Faulted
method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted
method of those activities just calls the next activity in the behavior.
A Catch
activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).
Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.
An activity within a state machine (using Automatonymous) is much different than an activity within Courier. Unfortunately, they both have the same name, which can create confusion.
When an activity throws an exception, the Faulted
method of the next activity in the behavior is called. If that method is a regular activity method (such as .Then, .Publish, etc.) it is skipped, since the Faulted
method of those activities just calls the next activity in the behavior.
A Catch
activity, however, can be used to catch the exception and execute a rescue behavior (which is a sequence of activities).
Either way, the Faulted method of the activity which throws an exception within the Execute method is not called. So yes, you should use a try/catch, but allow the exception to flow back out of the Execute method so that the behavior handles it properly.
answered Nov 24 at 3:40
Chris Patterson
8,2722329
8,2722329
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
add a comment |
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
Yeah, that's what I expected, got a bit confused after talking to Alexey. Thanks for the answer. That explains why my activities' .Faulted were not executed. In the end in states where activities are executed I've added the Catch and publish an event with the exception details to be handled by another activity created just for exception mitigation.
– Slowacki
Nov 29 at 17:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432308%2fhow-to-trigger-the-execution-of-the-compensation-flow-for-the-activities-used-wi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Automatonymous state machines are used for sagas and Activities are used for the Courier. You need to use the Courier to execute your activities and make the fallbacks to work.
– Alexey Zimarev
Nov 22 at 15:14
Hm, that feels a bit unintuitive providing that using Activities is allowed out-of-the-box when modelling the state machine and the Faulted method has to be implemented for each and every of them. Anyway, thanks for the information. I think I'll rewrite the compensation using the Catch methods in state machine itself.
– Slowacki
Nov 22 at 15:23
I am not sure, maybe I am missing something but I never have seen activities being used in Automatonymous state machines.
– Alexey Zimarev
Nov 22 at 15:33
You can add the activities to your state machine through the Activity extension method, if you want to use a factory: github.com/MassTransit/MassTransit/blob/develop/src/… Or just through the .Execute if you want to instantiate them on the spot: github.com/MassTransit/Automatonymous/blob/develop/src/…
– Slowacki
Nov 22 at 15:40