Do the events that occur when a command has executed in a CQRS-System have the same id as the Command, so that they can be associated to the command.
I´m currently implementing Saga´s in my CQRS-System and as far as i understand the concept of sagas is that they handle specific events to then define and execute commands to complete the process that is represented by the Saga.
My problem now is that how does the Saga know that the event that it is handling is the event it is waiting for.
Should i store the Id of the command that gets passed to the CommandBus in the Saga to wait for an event with the same Id? What if the execution of the command results in many diffrent events, do they all have the same Id?
For sagas, there has to be some correlating key on the constituent messages. Sometimes this can be a natural business domain key, such as OrderId. Other times a globally unique key is more appropriate such as a Guid. This key correlates messages related to a single task implemented by the saga.
In your case it seems that this correlating ID is the ID of the command which starts the saga.
Yes. If you can assert that this ID is unique and fully identifies the task which the saga implements then this should be the correlating ID of the saga.
They all share a correlation ID, but I don’t think of it as an ID for the event. The event may have an individual ID on its own, but for the saga to function, it has to have a correlation ID.