Hi
I am currently looking into CommonDomain SagaBase implementation and as far as I understand there is only one correlation id, which I can use to retrieve my Saga from event store.
I've faced some issues using this approach. Will try to describe my situation:
1. UI sends CreateUser()
2. UserCommandHandler handles this and save new User aggregate with some event, like: UserCreationRequestPlaced:
3. UserCreationRouter handles this event and route this into UserCreationSaga like this:
var sagaId = event.UserId;
var saga = _repository.GetById<UserCreationSaga>(sagaId);
if (saga.Id == Guid.Empty)
{
saga = new UserCreationSaga();
saga.Transition(event);
_repository.Save(saga,cmd.Id,null);
}
else
{
Log.WarnFormat("Command CreateUser arrived more than once. Cmd id: {0}" ,sagaId);
}
4. UserCreationSaga emits some external command, say ExternalSystemCreateUser using source command id as a correlation id, so that I could find my saga later.
5. UserCreationRouter handles 2 kind of events: ExternalSystemUserCreated, ExternalSystemUserCreationFailed and routes this events respectively to the saga:
var sagaId = ev.UserId;
var saga = _repository.GetById<UserCreationSaga>(sagaId);
if (saga.Id != Guid.Empty)
{
saga.Transition(event);
_repository.Save(saga, cmd.Id, null);
}
else
{
Log.WarnFormat("For some reason I can't find saga: {0}" , sagaId);
}
6. UserCreationSaga emits a command MarkUserAsCreated or MarkUserAsFailed
7. UserCommandHandler recieves those command and everything is fine
All is simple and straight forward. Correct me if something wrong here.
So my question:
Imagine that I have a need to create a couple of users, one by one. I've got a dedicated command for this, say CreateUsers(firstUserName, secondUserName).
How would you do this, having in mind my previous saga.
1. As I can see, we will need one more SagaRouter and one more Saga, right?
2. Do I have to have one more aggregate for CreateUsers command? So that I could save it first and it emitted the event, some thing like: TwoUsersCreationRequestPlaced - this one will start the saga
3. So we aggreed that TwoUsersCreationRequestPlaced will be our initiating event with some id which we took from the initial command.
4. And here is I should send a couple of CreateUser() commands to initiate my first sagam if to be recise 2 instances of them
5. I should wait for couple events which will be emmited by User aggregate after this commands MarkUserAsCreated or MarkUserAsFailed.
And here I got lost: I can't find how correlation ids work here. :(