I am trying to find help on designing a Saga in NServiceBus 5.x that is started by 2 or more messages. This means that the saga will not start with a single message, but all messages must be present before the saga starts.
I don't quite understand how that would work, and there are no samples or examples to be found anywhere.
I read a couple of books that clearly state it's perfectly fine to have a saga started by several messages.
What I don't get is how the saga is found when you need e.g. 3 messages to start the saga. All 3 messages have to arrive, in any order, before the saga can "start". How does this affect my choice of the [Unique] attribute?
Example: I need saga that is "unique"ly identified by three IDs "StoreID", "ComputerID", "UserID". Those three IDs would arrive in three distinct commands, Message1, Message2, Message3.
public class MySaga : Saga<MySagaData>,
IAmStartedByMessages<Message1>,
IAmStartedByMessages<Message2>,
IAmStartedByMessages<Message3>
{ ...
}
Should MySagaData have the [Unique] attribute on three properties?
public class MySagaData
{
[Unique]
public int StoreId {get;set;}
[Unique]
public int ComputerId {get;set;}
[Unique]
public int UserId {get;set;}
}
Or do I have to create readonly property concatenating those three?
When Message1 and Message3 arrive, the saga can't be started. Message2 is missing.
Then another Message1 arrives.
Then Message2 arrives. (completing the first saga, so it can be started)
What about the second Message1?
How would this be handled?
Sagas do not support the pattern you are describing. IAmStartedByMessages directives are applied with an ANY, rather than ALL, semantic.
Broadly, you have two options;