Hi Allard,
I have a question about how to notify the client about a failure when
using a Saga (I'm aware that I could do the same with "eventual
consistency" by simply doing a query in command handler of step "2.").
In the "Meta CQRS" application we have two aggregates: "Aggregate" and
"Operation" ("Operation" is not modeled as a child entity of
"Aggregate" because it's referenced by other third party aggregates).
RULES:
1) An "Operation" belongs to exactly one "Aggregate" (modeled by a
"parentAggregateId" inside the operation)
2) The name of an operation is unique inside the aggregate (modeled by
a list of operation names inside the aggregate)
SAGA:
1. [CLIENT]
CreateOperationCommand(operationId, operationName, parentAggregateId)
2. [COMMAND HANDLER]
handleCreateOperationCommand(..)
new Operation(operationId, operationName, parentAggregateId)
// Does NOT store "parentAggregateId" yet!
=> OperationCreatedEvent(operationId, operationName,
parentAggregateId)
3. [SAGA]
handleOperationCreatedEvent(..)
AddOperationCommand(parentAggregateId, operationName, operationId)
4. [COMMAND HANDLER]
handleAddOperationCommand(..)
parentAggregate.addOperation(operationName, operationId)
a) OK
=> OperationAddedEvent(parentAggregateId, operationName,
operationId)
b) DuplicateException
=> AddOperationFailedEvent(parentAggregateId, operationName,
operationId)
5. [SAGA]
handleOperationAddedEvent(..)
AssignAggregateCommand(operationId, parentAggregateId)
6. [COMMAND HANDLER]
handleAssignAggregateCommand(..)
operation.assign(parentAggregateId)
=> AggregateAssignedEvent(operationId, parentAggregateId)
7. [COMMAND HANDLER]
handleAddOperationFailedEvent(..)
operation.delete()
=> OperationDeletedEvent(operationId)
How do I notify the client about this failure? (The client received an
"OK" in step "1.")
Cheers,
Michael