NSaga icon indicating copy to clipboard operation
NSaga copied to clipboard

Allow for multiple sagas to be InitiatedBy<> and ConsumerOf<> the same message

Open Place1 opened this issue 6 years ago • 3 comments

In my usecase i'd like two different sagas (that don't know about eachother) to be able to consume the same message type. Currently this doesn't seem possible as NSaga's design seems to assume that Sagas will never be initiatedby or consume the same message types. For example; in the mediator it's expecting 1 saga for a given initiating message.

Currently I have to work around this issue by copy/pasting my message types so that each saga has it's own messages, even though they do the same thing.

For context, i have raw messages from a queue automatically being converted into saga messages.

Place1 avatar Jan 18 '19 03:01 Place1

@Place1 So if we get a message that starts multiple sagas, which one of the sagas should start? All of them? If there is a message that can be consumed by multiple sagas, which one should consume the message? What about order?

trailmax avatar Jan 18 '19 09:01 trailmax

@Place1 Also what should happen with CorrelationId of saga when multiple sagas are started by the same message?

trailmax avatar Jan 18 '19 09:01 trailmax

Good questions that i'm not 100% sure how to answer yet, but here are my thoughts:

if we get a message that starts multiple sagas, which one of the sagas should start?

I think if the message can initiate<> many sagas, they should all start.

If there is a message that can be consumed by multiple sagas, which one should consume the message?

again, i think they should all run.

What about order?

order is tricky. i think NSaga should not guarantee any execution order. Perhaps NSaga can implement an interface that allows the ordering behavior to be controlled. Library users could then implement this behavior if they need specific ordering.

what should happen with CorrelationId of saga when multiple sagas are started by the same message?

I think this is a tricky question. Perhaps correlation Ids should be prefixed with something that identifies the saga. The mediator should then handle this when passing messages to sagas. The saga identifier could also be useful to map an OperationResult to the particular Saga that returned it.

Place1 avatar Jan 21 '19 01:01 Place1