Featured post
nservicebus - Impossible to have two sagas that handle the same message type -
i have 2 different sagas (i mean saga types) handle same message.
public class attachmessagetobugsaga : tpsaga<attachmessagetobugsagadata>, iamstartedbymessages<messageisnotattached>, ihandlemessages<messageattachedtogeneralmessage> { public override void configurehowtofindsaga() { configuremapping<messageattachedtogeneralmessage>( saga => saga.id, message => message.sagaid ); } public void handle(messageisnotattachedtobug message) { send(new attachmessagetogeneralcommand { messageid = 66, generalid = 13 }); } public void handle(messageattachedtogeneralmessage message) { //do stuf fhere } } public class attachmessagetobugsagadata : icontainsagadata { public guid id { get; set; } public string originator { get; set; } public string originalmessageid { get; set; } } public class attachmessagetorequestsaga : tpsaga<attachmessagetorequestsagadata>, iamstartedbymessages<messageisnotattachedtorequest>, ihandlemessages<messageattachedtogeneralmessage> { public override void configurehowtofindsaga() { configuremapping<messageattachedtogeneralmessage>( saga => saga.id, message => message.sagaid ); } public void handle(messageisnotattachedmessagetorequest message) { //do stuff here } public void handle(messageattachedtogeneralmessage message) { //do stuff here } } public class attachmessagetorequestsagadata : icontainsagadata { public guid id { get; set; } public string originator { get; set; } public string originalmessageid { get; set; } }
when run sample exception :
system.invalidcastexception: unable cast object of type 'mycustomplugin.attachmessagetogeneralsagadata' type 'mycustomplugin.attachmessagetorequestsagadata'.
i understand why happens, still need workaround. tried implement own ifindsagas class :
public class sagafinder : ifindsagas<attachmessagetogeneralsagadata>.using<messageattachedtogeneralmessage>, ifindsagas<attachmessagetorequestsagadata>.using<messageattachedtogeneralmessage>, ifindsagas<attachmessagetorequestsagadata>.using<messageisnotattachedtorequest>, ifindsagas<attachmessagetorequestsagadata>.using<messageisnotattachedtobug> { attachmessagetogeneralsagadata ifindsagas<attachmessagetogeneralsagadata>.using<messageattachedtogeneralmessage>.findby(messageattachedtogeneralmessage message) { return objectfactory.getinstance<attachmessagetogeneralsagadata>(); } attachmessagetorequestsagadata ifindsagas<attachmessagetorequestsagadata>.using<messageattachedtogeneralmessage>.findby(messageattachedtogeneralmessage message) { return objectfactory.getinstance<attachmessagetorequestsagadata>(); } public attachmessagetorequestsagadata findby(messageisnotattachedtorequest message) { return new attachmessagetorequestsagadata(); } public attachmessagetorequestsagadata findby(messageisnotattachedtobug message) { return new attachmessagetorequestsagadata(); } }
but not finders "messageattachedtogeneralmessage". please tell me if there other workaround, or how make example working.
i'm not sure having more 1 saga within same process boundary works - @ least, i've had problems too. it's better (in general) have sagas separated 2 different processes anyway, because otherwise cause lot of locking , potentially deadlocks on saga storage.
is message handled 2 sagas sent or published? if it's published (or can made to), easy separate sagas 2 separate assemblies. sure manually call bus.subscribe() message type in each saga, since sagas don't auto-subscribe messages listed in app.config.
if message sent, , there's nothing can change it, create central handler existing message type either publishes second message type go both sagas, or sends 2 separate messages each saga.
- Get link
- X
- Other Apps
Comments
Post a Comment