Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a NserviceBus saga be started by AND handle the same message?

Tags:

nservicebus

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

like image 310
Paul C Huff Avatar asked Oct 23 '25 09:10

Paul C Huff


2 Answers

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<>.

like image 168
Davin Tryon Avatar answered Oct 26 '25 06:10

Davin Tryon


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.

like image 22
stephenl Avatar answered Oct 26 '25 06:10

stephenl