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

让人想犯罪 __ 提交于 2019-12-07 12:13:07

问题


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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/8466723/can-i-have-a-nservicebus-saga-be-started-by-and-handle-the-same-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!