Reputation: 93
Quick question: I have a saga that can have a scenario where it needs to handle a message that could come in under two situations. One where the saga is still open and one where the saga has been marked as complete.
If the saga is open, great, continue as normal. If the saga is not open it needs to to start a new saga. What is the best practice to handle this situation? IHandleMessages<>
works great, obviously, if the saga is open. But won't IAmStartedByMessages<>
cause two sagas to be open? This would be bad. Thanks
Upvotes: 4
Views: 1644
Reputation: 67296
IAmStartedByMessages<>
will not cause 2 sagas to be open if an already open saga can be resolved. You should be fine to just use IAmStartedByMessages<>
with no need for an IHandleMessages<>
.
Upvotes: 5
Reputation: 402
As I see from NserviceBus sources new saga will not be started if some saga which handles message found. (I checked NBus 2.0)
So your scenario should work correctly. You may easily check this from sample application.
Still, situation you describe is rather strange. I would prefer to have two message types, one for saga start, another for saga work.
Upvotes: 1
Reputation: 3129
You can still handle a message using IAmStartedByMessages<> as long as you make sure you include it in your ConfigureMapping override. That way, depending on how you find existing saga's, you will either return an existing instance or create a new one. HTH.
Upvotes: 2